Illuminate\Queue\Worker::daemon PHP Method

daemon() public method

Listen to the given queue in a loop.
public daemon ( string $connectionName, string $queue, WorkerOptions $options ) : void
$connectionName string
$queue string
$options WorkerOptions
return void
    public function daemon($connectionName, $queue, WorkerOptions $options)
    {
        $lastRestart = $this->getTimestampOfLastQueueRestart();
        while (true) {
            $job = $this->getNextJob($this->manager->connection($connectionName), $queue);
            $this->registerTimeoutHandler($job, $options);
            if ($job && $this->daemonShouldRun($options)) {
                $this->runJob($job, $connectionName, $options);
            } else {
                $this->sleep($options->sleep);
            }
            if ($this->memoryExceeded($options->memory) || $this->queueShouldRestart($lastRestart)) {
                $this->stop();
            }
        }
    }

Usage Example

示例#1
4
 /**
  * Run the worker instance.
  *
  * @param  string  $connection
  * @param  string  $queue
  * @param  int  $delay
  * @param  int  $memory
  * @param  bool  $daemon
  * @return array
  */
 protected function runWorker($connection, $queue, $delay, $memory, $daemon = false)
 {
     if ($daemon) {
         $this->worker->setCache($this->laravel['cache']->driver());
         $this->worker->setDaemonExceptionHandler($this->laravel['Illuminate\\Contracts\\Debug\\ExceptionHandler']);
         return $this->worker->daemon($connection, $queue, $delay, $memory, $this->option('sleep'), $this->option('tries'));
     }
     return $this->worker->pop($connection, $queue, $delay, $this->option('sleep'), $this->option('tries'));
 }