Discuz教程网

[二次开发] discuz x1.5 计划任务改为系统层执行,加强计划任务执行、降低用户端执行压力

[复制链接]
authicon dly 发表于 2012-8-3 20:26:11 | 显示全部楼层 |阅读模式
discuz x1.5 计划任务改为系统层执行,加强计划任务执行、降低用户端执行压力
  1. 1、添加cronrun.php文件

  2. define('APPTYPEID', 1);
  3. define('CURSCRIPT', 'cronrun');
  4. if($argv['1'] != 'start'){

  5. header("HTTP/1.1 301 Moved Permanently");
  6. header("location: index.php");
  7. exit();
  8. }
  9. @ignore_user_abort(TRUE);
  10. @set_time_limit(0);
  11. require './source/class/class_core.php';
  12. $discuz = & discuz_core::instance();
  13. $discuz->init();
  14. $timestamp = time();
  15. $t = $timestamp + 600;
  16. if($timestamp <= @filemtime('data/run.lock')){
  17. runlog("runlog.log",'limit-run');
  18. exit();
  19. }

  20. @touch('data/run.lock', $t);
  21. $query = DB::query("SELECT * FROM ".DB::table('common_cron')." WHERE `available`>'0' AND `nextrun`<='$timestamp' ORDER BY nextrun");
  22. while($cron = DB::fetch($query)) {
  23. $cron['filename'] = str_replace(array('..', '/', '\\'), '', $cron['filename']);
  24. $cronfile = DISCUZ_ROOT.'./source/include/cron/'.$cron['filename'];
  25. $cron['minute'] = explode("\t", $cron['minute']);
  26. discuz_cron::setnextime($cron);
  27. if(!@include_once $cronfile) {
  28. runlog("runlog.log",'Not find cronfile:'.$cronfile);
  29. continue;
  30. }
  31. runlog("runlog.log",$cronfile);
  32. }
  33. @touch('data/run.lock', $timestamp);



  34. 2、将程序自动执行计划任务关闭
  35. class_core.php
  36. var $init_cron = false;


  37. 3、服务器添加系统计划任务 crontab
  38. */1 * * * * cd /data/wwwroot/bbs/ && chmod +x cronrun.php && /usr/local/php/bin/php cronrun.php start
复制代码



上一篇:仿discuz 上传头像
下一篇:解决discuz x1.5 用户窜号问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 01:55

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表