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

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

PHP中文网
Release: 2016-05-25 17:10:51
Original
1001 people have browsed it

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);
Copy after login

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

class_core.php
var $init_cron = false;
Copy after login


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

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

           

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template