InitCron.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\event;
  11. use think\facade\Cache;
  12. /**
  13. * 初始化计划任务启动
  14. * @author Administrator
  15. *
  16. */
  17. class InitCron
  18. {
  19. public function handle()
  20. {
  21. if (defined('BIND_MODULE') && BIND_MODULE === 'install') {
  22. return;
  23. }
  24. $last_time = Cache::get("cron_last_load_time");
  25. if (empty($last_time)) {
  26. $last_time = 0;
  27. }
  28. $module = request()->module();
  29. if ($module != 'cron') {
  30. if (!defined('CRON_EXECUTE') && time() - $last_time > 100) {
  31. defined('CRON_EXECUTE') or define('CRON_EXECUTE', 1);
  32. $url = url('cron/task/cronExecute');
  33. $ch = curl_init();
  34. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  35. curl_setopt($ch, CURLOPT_HEADER, true);
  36. curl_setopt($ch, CURLOPT_URL, $url);
  37. curl_setopt($ch, CURLOPT_TIMEOUT, 1);
  38. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  39. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  40. curl_exec($ch);
  41. }
  42. }
  43. }
  44. }