Skip to content

Instantly share code, notes, and snippets.

@reshadman
Created June 28, 2014 18:00
Show Gist options
  • Save reshadman/d178d05f874e2ef6a40d to your computer and use it in GitHub Desktop.
Save reshadman/d178d05f874e2ef6a40d to your computer and use it in GitHub Desktop.
Worker long running daemon
<?php
public function daemon($connectionName, $queue = null, $delay = 0, $memory = 128, $sleep = 3, $maxTries = 0)
{
$lastRestart = $this->getTimestampOfLastQueueRestart();
while (true)
{
if ($this->daemonShouldRun())
{
$this->runNextJobForDaemon(
$connectionName, $queue, $delay, $sleep, $maxTries
);
}
else
{
$this->sleep($sleep);
}
if ($this->memoryExceeded($memory) || $this->queueShouldRestart($lastRestart))
{
exec('php artisan queue:work --daemon > /dev/null 2>&1 &');
$this->stop();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment