Skip to content

Commit

Permalink
register timeout handlers on php 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 3, 2016
1 parent 6b5705d commit cc9e1f0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
$lastRestart = $this->getTimestampOfLastQueueRestart();

while (true) {
$this->registerTimeoutHandler($options);

if ($this->daemonShouldRun()) {
$this->runNextJob($connectionName, $queue, $options);
} else {
Expand All @@ -83,6 +85,29 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
}
}

/**
* Register the worker timeout handler (PHP 7.1+).
*
* @param WorkerOptions $options
* @return void
*/
protected function registerTimeoutHandler(WorkerOptions $options)
{
if (version_compare(PHP_VERSION, '7.1.0') < 0 || ! extension_loaded('pcntl')) {
return;
}

pcntl_async_signals(true);

pcntl_signal(SIGALRM, function () {
$this->exceptions->report(new TimeoutException("A queue worker timed out while processing a job."));

exit(1);
});

pcntl_alarm($options->timeout + $options->sleep);
}

/**
* Determine if the daemon should process on this iteration.
*
Expand Down

0 comments on commit cc9e1f0

Please sign in to comment.