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),
            'shutdown'     => false,
            '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);

            // PHP 7.1 allows async signals
            if (function_exists('pcntl_async_signals')) {
                pcntl_async_signals(true);
            } else {
                declare(ticks = 1);
            }
            foreach ($this->signalHandlerMapping as $signalName => $signalHandler) {
                pcntl_signal($signalName, array($this, $signalHandler));
            }
        }

        register_shutdown_function(array($this, 'unregister'));

        Event::fire(Event::WORKER_REGISTER, $this);
    }
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),
            'shutdown'     => false,
            '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);

            // PHP 7.1 allows async signals
            if (function_exists('pcntl_async_signals')) {
                pcntl_async_signals(true);
            } else {
                declare(ticks = 1);
            }
            foreach ($this->signalHandlerMapping as $signalName => $signalHandler) {
                pcntl_signal($signalName, array($this, $signalHandler));
            }
        }

        register_shutdown_function(array($this, 'unregister'));

        Event::fire(Event::WORKER_REGISTER, $this);
    }
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 ) , 'shutdown' => false , '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 ) ; // PHP 7.1 allows async signals if ( function_exists ( 'pcntl_async_signals' ) ) { pcntl_async_signals ( true ) ; } else { declare ( ticks = 1 ) ; } foreach ( $ this -> signalHandlerMapping as $ signalName => $ signalHandler ) { pcntl_signal ( $ signalName , array ( $ this , $ signalHandler ) ) ; } } register_shutdown_function ( array ( $ this , 'unregister' ) ) ; Event :: fire ( Event :: WORKER_REGISTER , $ this ) ; }
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
Register this worker in Redis and signal handlers that a worker should respond to