Skip to content

Instantly share code, notes, and snippets.

@muyaedward
Forked from mauris/queue-ensure.php
Created July 7, 2018 23:01
Show Gist options
  • Save muyaedward/1d5c96affa83fc4a1b1e30444f413edc to your computer and use it in GitHub Desktop.
Save muyaedward/1d5c96affa83fc4a1b1e30444f413edc to your computer and use it in GitHub Desktop.
Laravel Artisan Queue Ensurer - Set a cron job to run this file periodically to ensure that Laravel's queue is processing all the time. If the queue listener stopped, restart it!
<?php
function runCommand ()
{
$command = 'php artisan queue:listen > /dev/null & echo $!';
$number = exec($command);
file_put_contents(__DIR__ . '/queue.pid', $number);
}
if (file_exists(__DIR__ . '/queue.pid')) {
$pid = file_get_contents(__DIR__ . '/queue.pid');
$result = exec('ps | grep ' . $pid);
if ($result == '') {
runCommand();
}
} else {
runCommand();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment