Skip to content

Instantly share code, notes, and snippets.

@kevinsmith
Forked from mauris/queue-ensure.php
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinsmith/16a207f53cfcfbcc3a4a to your computer and use it in GitHub Desktop.
Save kevinsmith/16a207f53cfcfbcc3a4a to your computer and use it in GitHub Desktop.
<?php
function runCommand ()
{
$command = 'php artisan queue:work --daemon --env=prod > /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 -p {$pid} | awk 'NR>1'");
if ($result == '') {
runCommand();
}
} else {
runCommand();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment