欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

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

程序员文章站 2022-05-24 19:50:53
...
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('data/run.lock')){
    runlog("runlog.log",'limit-run');
    exit();
}

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