geoffs3310 geoffs3310 - 2 years ago 95
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:

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 Source

I use this, in a command file:

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

while ($entry = $queue->pop()) {
    // your task
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download