首頁 >php教程 >PHP源码 >discuz x1.5 计划任务改为系统层执行

discuz x1.5 计划任务改为系统层执行

PHP中文网
PHP中文网原創
2016-05-25 17:10:511001瀏覽

1、添加cronrun.php文件

define('APPTYPEID', 1);
define('CURSCRIPT', 'cronrun');
if($argv['1'] != 'start'){
 
   header("HTTP/1.1 301 Moved Permanently");
    header("location: index.php");
    exit();
}
@ignore_user_abort(TRUE);
@set_time_limit(0);
require './source/class/class_core.php';
$discuz = & discuz_core::instance();
$discuz->init();
$timestamp = time();
$t = $timestamp + 600;
if($timestamp <= @filemtime(&#39;data/run.lock&#39;)){
    runlog("runlog.log",&#39;limit-run&#39;);
    exit();
}

@touch(&#39;data/run.lock&#39;, $t);
$query = DB::query("SELECT * FROM ".DB::table(&#39;common_cron&#39;)." WHERE `available`>&#39;0&#39; AND `nextrun`<=&#39;$timestamp&#39; ORDER BY nextrun");
while($cron = DB::fetch($query)) {
    $cron[&#39;filename&#39;] = str_replace(array(&#39;..&#39;, &#39;/&#39;, &#39;\\&#39;), &#39;&#39;, $cron[&#39;filename&#39;]);
    $cronfile = DISCUZ_ROOT.&#39;./source/include/cron/&#39;.$cron[&#39;filename&#39;];
    $cron[&#39;minute&#39;] = explode("\t", $cron[&#39;minute&#39;]);
    discuz_cron::setnextime($cron);
    if(!@include_once $cronfile) {
        runlog("runlog.log",&#39;Not find cronfile:&#39;.$cronfile);
        continue;
    }
    runlog("runlog.log",$cronfile);
}
@touch(&#39;data/run.lock&#39;, $timestamp);

   2、将程序自动执行计划任务关闭

class_core.php
var $init_cron = false;


3、服务器添加系统计划任务 crontab

*/1 * * * * cd /data/wwwroot/bbs/ && chmod +x cronrun.php && /usr/local/php/bin/php cronrun.php start

           

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn