龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

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

时间:2014-07-22 14:51来源: 作者: 点击:
分享到:
加强计划任务执行、降低用户端执行压力 br / 更多请查看 a target=_blank href=http://blog.sina.com.cn/ittuan rel=nofollow团长的编程杂记铺 /a a target=_blank href=http://blog.sina.com.cn/ittuan rel=nofollow新浪博客
加强计划任务执行、降低用户端执行压力
更多请查看 团长的编程杂记铺 新浪博客 http://blog.sina.com.cn/ittuan

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
精彩图集

赞助商链接