Laravel 队列只运行一项工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37207290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel queue only run one job
提问by dungdoan
In my table "jobs" have 5 jobs, i used the process "php artisan queue:listen" on localhost then it ran all jobs and finished. But when i used this process on server then it only once ran one jobs (same "php artisan queue:work"). I use queue_driver is "database".
在我的“工作”表中有 5 个工作,我在本地主机上使用了“php artisan queue:listen”进程,然后它运行了所有工作并完成了。但是当我在服务器上使用这个过程时,它只运行一次作业(相同的“php artisan queue:work”)。我使用的 queue_driver 是“数据库”。
回答by haakym
TL;DR
TL; 博士
php artisan queue:work
= run one queued job and stop
php artisan queue:work
= 运行一个排队的作业并停止
php artisan queue:listen
= run all queued jobs and listen for more until stopped
php artisan queue:listen
= 运行所有排队的作业并监听更多直到停止
Further detail:
更多细节:
How are you running the commands? Are you just opening a terminal and running it or do you have a cron job to run at intervals?
你是如何运行命令的?你只是打开一个终端并运行它还是你有一个定时运行的定时任务?
If you're just opening a terminal and running php artisan queue:work
will complete one task on the queue then stop, whereas if you run php artisan queue:listen
it will process all the jobs in the queue and continue to listen for any further jobs until it is stopped.
如果您只是打开一个终端并且运行php artisan queue:work
将完成队列中的一项任务然后停止,而如果您运行php artisan queue:listen
它将处理队列中的所有作业并继续侦听任何进一步的作业直到它停止。
Read further in the docs regarding queue:work
:
Starting The Queue Listener
Laravel includes an Artisan command that will run new jobs as they are pushed onto the queue. You may run the listener using the queue:listen command:
php artisan queue:listen
Processing The First Job On The Queue
To process only the first job on the queue, you may use the queue:work command:
php artisan queue:work
启动队列侦听器
Laravel 包含一个 Artisan 命令,该命令将在将新作业推送到队列时运行它们。您可以使用 queue:listen 命令运行侦听器:
php artisan queue:listen
处理队列中的第一个作业
要仅处理队列中的第一个作业,您可以使用 queue:work 命令:
php artisan queue:work
What you should be doing?
你应该做什么?
I am guessing what you ideally want to do on your server is set up a cron job to run continuously at intervals and have it run queue:work
. Better yet, acquaint yourself with the docs and make a decision after that.
我猜您理想情况下想要在您的服务器上做的是设置一个 cron 作业以间隔连续运行并让它运行queue:work
。更好的是,熟悉文档并在此之后做出决定。
See similar question answered here: What is the difference between queue:work --daemon and queue:listen
请参阅此处回答的类似问题:queue:work --daemon 和 queue:listen 之间有什么区别
回答by igaster
Update - Laravel 5.5+
更新 - Laravel 5.5+
Just use:
只需使用:
php artisan queue:work --once
php artisan queue:work --once