由于项目的需求,决定采用laravel的队列任务来实现
环境如下:laravel 5.1;php 7.1.3;运行环境window
准备工作:
#修改.env文件QUEUE_DRIVER=database
php artisan queue:tablephp artisan migrate
php artisan make:job SendReminderSms
$staff = Staff::find($all_cache_need[0]);//推送任务$this->dispatch(new SendRemindSms($staff));
修改任务类
............../*** 执行任务* Execute the job.** @return void*/public function handle(){$phone = $this->staff->phone;if(!empty($phone)){\sendSms($phone);//准备执行第二次尝试if($this->attempts()<2){$this->release(20);}}}..............
#该运行方式比queue:listen更加节省内存以及cpu,进程窗口不可关闭php artisan queue:work --daemon