/** * Register this worker in Redis and signal handlers that a worker should respond to * * - TERM: Shutdown immediately and stop processing jobs * - INT: Shutdown immediately and stop processing jobs * - QUIT: Shutdown after the current job finishes processing * - USR1: Kill the forked child immediately and continue processing jobs */ public function register() { $this->log('Registering worker <pop>' . $this . '</pop>', Logger::NOTICE); $this->redis->sadd(self::redisKey(), $this->id); $this->redis->hmset(self::redisKey($this), array('started' => microtime(true), 'hostname' => (string) $this->host, 'pid' => getmypid(), 'memory' => memory_get_usage(), 'memory_limit' => $this->memoryLimit, 'queues' => implode(',', $this->queues), 'blocking' => $this->blocking, 'status' => $this->status, 'interval' => $this->interval, 'timeout' => $this->timeout, 'processed' => 0, 'cancelled' => 0, 'failed' => 0, 'job_id' => '', 'job_pid' => 0, 'job_started' => 0)); if (function_exists('pcntl_signal')) { $this->log('Registering sig handlers for worker ' . $this, Logger::DEBUG); declare (ticks=1); pcntl_signal(SIGTERM, array($this, 'sigForceShutdown')); pcntl_signal(SIGINT, array($this, 'sigForceShutdown')); pcntl_signal(SIGQUIT, array($this, 'sigShutdown')); pcntl_signal(SIGUSR1, array($this, 'sigCancelJob')); pcntl_signal(SIGUSR2, array($this, 'sigPause')); pcntl_signal(SIGCONT, array($this, 'sigResume')); pcntl_signal(SIGPIPE, array($this, 'sigWakeUp')); } register_shutdown_function(array($this, 'unregister')); Event::fire(Event::WORKER_REGISTER, $this); }