InitCron.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. declare (strict_types = 1);
  13. namespace app\event;
  14. use think\facade\Config;
  15. use think\facade\Cache;
  16. /**
  17. * 初始化计划任务启动
  18. * @author Administrator
  19. *
  20. */
  21. class InitCron
  22. {
  23. public function handle()
  24. {
  25. if (defined('BIND_MODULE') && BIND_MODULE === 'install') {
  26. return;
  27. }
  28. $last_time = Cache::get("cron_last_load_time");
  29. if (empty($last_time)) {
  30. $last_time = 0;
  31. }
  32. $module = request()->module();
  33. if($module != 'cron')
  34. {
  35. if (!defined('CRON_EXECUTE') && time() - $last_time > 100) {
  36. defined('CRON_EXECUTE') or define('CRON_EXECUTE', 1);
  37. $url = url('cron/task/phpCron');
  38. $ch = curl_init();
  39. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  40. curl_setopt($ch, CURLOPT_HEADER, true);
  41. curl_setopt($ch, CURLOPT_URL, $url);
  42. curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  43. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  44. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  45. curl_exec($ch);
  46. }
  47. }
  48. }
  49. }