简体   繁体   中英

Laravel queue only run one job

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".

TL;DR

php artisan queue:work = run one queued job and stop

php artisan queue:listen = run all queued jobs and listen for more until stopped

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.

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

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.

See similar question answered here: What is the difference between queue:work --daemon and queue:listen

Update - Laravel 5.5+

Just use:

php artisan queue:work --once

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM