Home  >  Article  >  php教程  >  discuz x1.5 计划任务改为系统层执行

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

PHP中文网
PHP中文网Original
2016-05-25 17:10:51975browse

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

           

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:coreseek中的一个小东西Next article:PHP二分查找实例