Laravel提供了开箱即用的队列服务,队列允许你延迟处理耗时的任务,比如发送电子邮件,直到稍后的时间。推迟这些耗时的任务可以大大加快应用程序的Web请求。1.生成队列表phpartisanqueue:tablephpartisanmigrate2.生成Job类这里我们添加队列操作phpartisanmake:jobSendReminderEmailSendReminderEmail.phpuser=$user;}/***执行作业。**@returnvoid*/publicfunctionhandle(){//打印调试\Log::info('sendreminderemailto'.$this->user->email);我们以UserModel为例,首先在构造方法中注入User类,然后在UsersController.php中使用dispatch加入队列,dispatch(newSendReminderEmail($用户));添加到队列后,我们需要在handle()方法中处理具体的业务逻辑,比如给具体的用户对象发送邮件,最后执行queue命令发送邮件phpartisanqueue:work
