Cron.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\console\command;
  3. use app\console\service\DailyBonus as DailyBonusService;
  4. use app\console\service\MonthlyBonusClear;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\input\Argument;
  8. use think\console\input\Option;
  9. use think\console\Output;
  10. use Workerman\Crontab\Crontab;
  11. use Workerman\Worker;
  12. class Cron extends Command
  13. {
  14. protected function configure()
  15. {
  16. log_record('aaa','error');
  17. $this->setName('croner')
  18. ->addArgument('status', Argument::REQUIRED, 'start/stop/reload/status/connections')
  19. ->addOption('d', null, Option::VALUE_NONE, 'daemon(守护进程)方式启动')
  20. ->setDescription('Cron Gold Command');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. $worker = new Worker();
  25. $worker->count = 4;
  26. // 设置时区,避免运行结果与预期不一致
  27. date_default_timezone_set('PRC');
  28. log_record('ccc','error');
  29. $worker->onWorkerStart = function ($worker) {
  30. log_record(date('ID--->'.$worker->id),'error');
  31. /* new Crontab('* * * * * *', function(){
  32. log_record(date('Y-m-d H:i:s'),'error');
  33. });*/
  34. // 每分钟的第1秒执行.00::05:01 todo
  35. //new Crontab('1 5 0 * * *', function(){
  36. /* new Crontab('1 * * * * *', function(){
  37. echo date('Y-m-d H:i:s')."\n";
  38. $service = new DailyBonusService;
  39. $service->calBonusMoney(10001);
  40. });*/
  41. // 每天的7点50执行,注意这里省略了秒位.20日 01:01:00秒 todo
  42. //new Crontab('1 1 20 * *', function(){
  43. /* new Crontab('1 * * * * *', function(){
  44. echo "monthly job!"."\n";
  45. $service = new MonthlyBonusClear();
  46. $service->clearBonusMoney(10001);
  47. });*/
  48. };
  49. Worker::runAll();
  50. }
  51. }