Laravel 队列
Laravel队列服务为各种不同的后台队列提供了统一的API允许推迟耗时任务(例如发送邮件的执行),从而大幅度提高web请求速度主要步骤:1、迁移队列需要的数据表cmdphp artisan queue:table //生成任务表。database下面migrationsphp artisan migrate //执行迁移,数据表多出来一个jobs表...
Laravel队列服务为各种不同的后台队列提供了统一的API
允许推迟耗时任务(例如发送邮件的执行),从而大幅度提高web请求速度
主要步骤:
1、迁移队列需要的数据表
cmd
php artisan queue:table //生成任务表。database下面migrations
php artisan migrate //执行迁移,数据表多出来一个jobs表
2、编写任务类
命令行创建任务类:php artisan make:job SendEmail //app目录下就会多一个jobs目录和文件
3、推送任务到队列
4、运行队列监听器
php artisan queue:listen
5、处理失败任务
php artisan queue:failed-table //建立迁移文件
php artisan migrate //创建迁移表 faild_jobs
php artisan queue:failed //查询失败的任务列表
php artisan queue:retry 1 //重新执行id为1的任务
php artisan queue:retry all //重新执行所有失败的任务
php artisan queue:forget 1 //删除id为1的失败的任务
php artisan queue:flush //删除所有失败的任务
配置文件地址:config/queue.php
.env中的QUEUE_DRIVER=database
更多推荐
所有评论(0)