geoffs3310 geoffs3310 - 7 months ago 17
PHP Question

How to process all items in queue and exit

I am using Laravel 5 on a LAMP stack server running Ubuntu. I am using the queue system:

http://laravel.com/docs/master/queues

I can see from the docs that there is the ability to run queue:listen which will listen forever and process past and future items in the queue.

There is also queue:work which just processes the first item in the queue.

Is there a way to just process every item in the queue and then stop listening?

I only want to process the queue periodically so how can I setup a cron job that will process the queue and then as soon as everything in the queue has been done just exit?

Answer

I use this, in a command file:

$queue = Queue::connection('yourqueueconnection');

while ($entry = $queue->pop()) {
    // your task
}