作者:魅由心生先_941 | 来源:互联网 | 2018-03-23 17:55
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