onSwooleWorkerStart
@param $serv
@param $workerId
761522
public function onSwooleWorkerStart($serv, $workerId)
    {
        setTimezone();
        $this->workerId = $workerId;
        //清除apc缓存
        if (function_exists('apc_clear_cache')) {
            apc_clear_cache();
        }
        if (function_exists('opcache_reset')) {
            opcache_reset();
        }
        // 重新加载配置
        $this->config = $this->config->load(getConfigDir());
        if (!$serv->taskworker) {//worker进程
            Start::setProcessTitle(getServerName() . "-Worker");
        } else {
            Start::setProcessTitle(getServerName() . "-Tasker");
        }
    }
667388
public function onSwooleWSClose($serv, $fd)
    {
        parent::onSwooleWSClose($serv, $fd);
        $uid = $this->getUidFromFd($fd);
        $this->unBindUid($uid, $fd);
    }
766767
public function onWorkerStart($serv, $workerId)
    {
        // Worker类型
        if (!$this->isTaskWorker()) {
            if ($workerId !== null) {
                $this->processType = Macro::PROCESS_WORKER;
                getInstance()->sysTimers[] = swoole_timer_tick(2000, function ($timerId) {
                    $this->statistics();
                });
            }
        } else {
            $this->processType = Macro::PROCESS_TASKER;
        }

        parent::onWorkerStart($serv, $workerId);
        if ($this->processType == Macro::PROCESS_WORKER || $this->processType == Macro::PROCESS_TIMER) {
            $this->initAsynPools();
            $this->initRedisProxies();
            $this->initMysqlProxies();

            //注册
            $this->asynPoolManager = new AsynPoolManager(null, $this);
            $this->asynPoolManager->noEventAdd();
            foreach ($this->asynPools as $pool) {
                if ($pool) {
                    $pool->workerInit($workerId);
                    $this->asynPoolManager->registerAsyn($pool);
                }
            }

            if (!empty($this->redisProxyManager)) {
                //redis proxy监测
                getInstance()->sysTimers[] = $this->server->tick(5000, function () {
                    foreach ($this->redisProxyManager as $proxy) {
                        $proxy->check();
                    }
                });
            }

            if (!empty($this->mysqlProxyManager)) {
                // mysql proxy监测
                getInstance()->sysTimers[] = $this->server->tick(5000, function () {
                    foreach ($this->mysqlProxyManager as $proxy) {
                        $proxy->check();
                    }
                });
            }
        }
    }
920307
public static function onStart($serv) {
		self::setProcessName(Yesf::app()->getConfig('name', Yesf::CONF_PROJECT) . ' master');
		$pidPath = rtrim(Yesf::app()->getConfig('pid', Yesf::CONF_SERVER), '/') . '/';
		try {
			file_put_contents($pidPath . Yesf::app()->getConfig('name', Yesf::CONF_PROJECT) . '_master.pid', $serv->master_pid);
			file_put_contents($pidPath . Yesf::app()->getConfig('name', Yesf::CONF_PROJECT) . '_manager.pid', $serv->manager_pid);
		} catch (\Exception $e) {
			//忽略写入错误
		}
	}
441430
public function initAsynPools($workerId)
    {
        $this->asynPools = [];
        if ($this->config->get('redis.enable', true)) {
            $this->addAsynPool('redisPool', new RedisAsynPool($this->config, $this->config->get('redis.active')));
        }
        if ($this->config->get('mysql.enable', true)) {
            $this->addAsynPool('mysqlPool', new MysqlAsynPool($this->config, $this->config->get('mysql.active')));
        }
        if ($this->config->get('error.dingding_enable', false)) {
            $this->addAsynPool('dingdingRest', new HttpClientPool($this->config, $this->config->get('error.dingding_url')));
        }
        $this->redis_pool = $this->asynPools['redisPool'] ?? null;
        $this->mysql_pool = $this->asynPools['mysqlPool'] ?? null;
    }
483992
public function onWorkerExit(SwServer $server, int $workerId)
    {
        // {{ log
        $this->get('logger')->info('Worker 进程重启退出', [
            'id' => $workerId
        ]);
        // }}

        $this->callProtocolMethod('onExit', $server, $workerId);
    }
142653
public function onWorkerStart(SwServer $server, int $workerId)
    {
        $workerType = $server->taskworker ? 'task' : 'worker';

        // {{
        $this->setRunUser();
        $this->setProcessName($workerType . ' #' . $workerId);
        // }}

        // {{ log
        $this->get('logger')->info('启动 Worker 进程', [
            'id' => $workerId,
            'pid' => $server->worker_pid,
            'type' => ucfirst($workerType)
        ]);
        // }}

        if ($workerType === 'worker') {
            // {{
            $this->bootWorkerStartItems($workerId);
            // }}
            $this->callProtocolMethod('onStart', $server, $workerId);
        }

        unset($workerType);
    }
22973
protected function start_lib_worker($worker_list, $timeouts = array()) {

        $thisWorker = new \GearmanWorker();

        $thisWorker->addOptions(GEARMAN_WORKER_NON_BLOCKING);

        $thisWorker->setTimeout(5000);

        foreach ($this->servers as $s) {
            $this->log("Adding server $s", GearmanManager::LOG_LEVEL_WORKER_INFO);
            // see: https://bugs.php.net/bug.php?id=63041
            try {
                $thisWorker->addServers($s);
            } catch (\GearmanException $e) {
                if ($e->getMessage() !== 'Failed to set exception option') {
                    throw $e;
                }
            }
        }

        foreach ($worker_list as $w) {
            $timeout = (isset($timeouts[$w]) ? $timeouts[$w] : null);
            $this->log("Adding job $w ; timeout: " . $timeout, GearmanManager::LOG_LEVEL_WORKER_INFO);
            $thisWorker->addFunction($w, array($this, "do_job"), $this, $timeout);
        }

        $start = time();

        while (!$this->stop_work) {

            if (@$thisWorker->work() ||
               $thisWorker->returnCode() == GEARMAN_IO_WAIT ||
               $thisWorker->returnCode() == GEARMAN_NO_JOBS) {

                if ($thisWorker->returnCode() == GEARMAN_SUCCESS) continue;

                if (!@$thisWorker->wait()) {
                    if ($thisWorker->returnCode() == GEARMAN_NO_ACTIVE_FDS) {
                        sleep(5);
                    }
                }

            }

            /**
             * Check the running time of the current child. If it has
             * been too long, stop working.
             */
            if ($this->max_run_time > 0 && time() - $start > $this->max_run_time) {
                $this->log("Been running too long, exiting", GearmanManager::LOG_LEVEL_WORKER_INFO);
                $this->stop_work = true;
            }

            if (!empty($this->config["max_runs_per_worker"]) && $this->job_execution_count >= $this->config["max_runs_per_worker"]) {
                $this->log("Ran $this->job_execution_count jobs which is over the maximum({$this->config['max_runs_per_worker']}), exiting", GearmanManager::LOG_LEVEL_WORKER_INFO);
                $this->stop_work = true;
            }

        }

        $thisWorker->unregisterAll();


    }
373332
public function start()
    {
        if ($this->isRunning()) {
            throw new StatusError('The worker pool has already been started.');
        }

        // Start up the pool with the minimum number of workers.
        $count = $this->minSize;
        while (--$count >= 0) {
            $worker = $this->createWorker();
            $this->idleWorkers->enqueue($worker);
        }

        $this->running = true;
    }
718305
public function onWorkerStop(Server $server,int $worker_id)
    {
        $this->fireServerEvent(SwooleEvent::ON_WORKER_STOP, [$server,$worker_id]);
    }
146923
public static function post(TaskInfo $taskInfo, $workerID = -1)
    {
        return ServerManage::getServer('main')->getSwooleServer()->task($taskInfo, $workerID, [$taskInfo->getTaskHandler(), 'finish']);
    }
888483
public static function routerBind($worker_connections, $client_connection, $cmd, $buffer)
    {
        if (!isset($client_connection->businessworker_address) || !isset($worker_connections[$client_connection->businessworker_address])) {
            $client_connection->businessworker_address = array_rand($worker_connections);
        }
        return $worker_connections[$client_connection->businessworker_address];
    }
72061
public function onWorkerStart($server)
    {
        if ($this->container->config->get('swoole.enable_coroutine', false)) {
            Runtime::enableCoroutine(true);
        }

        $this->clearCache();

        $this->container->event->trigger('swoole.workerStart', func_get_args());

        // don't init app in task workers
        if ($server->taskworker) {
            $this->setProcessName('task process');

            return;
        }

        $this->setProcessName('worker process');

        $this->prepareApplication();

        if ($this->isServerWebsocket) {
            $this->prepareWebsocketHandler();
            $this->loadWebsocketRoutes();
        }
    }
287992
public function onWorkerStop(SwServer $server, int $workerId)
    {
        $workerType = $server->taskworker ? 'task' : 'worker';

        // {{ log
        $this->get('logger')->info('结束 Worker 进程', [
            'id' => $workerId,
            'type' => ucfirst($workerType)
        ]);
        // }}

        if ($workerType === 'worker') {
            $this->shutdownWorkerStartItems();
            $this->callProtocolMethod('onStop', $server, $workerId);
        }

        unset($workerType);
    }
928368
public void start() {
		this.workerThread = new Thread(this);
		System.out.println("starting worker thread");
		this.workerThread.start();
		System.out.println("worker thread started");
	}
134575
public function onWorkerStart($serv, $workerId)
    {
        $this->initAsynPools();
        $this->initRedisProxies();
        //注册
        $this->asynPoolManager = new AsynPoolManager(null, $this);
        $this->asynPoolManager->noEventAdd();
        foreach ($this->asynPools as $pool) {
            if ($pool) {
                $pool->workerInit($workerId);
                $this->asynPoolManager->registerAsyn($pool);
            }
        }

        //redis proxy监测
        getInstance()->sysTimers[] = swoole_timer_tick(5000, function () {
            if (!empty($this->redisProxyManager)) {
                foreach ($this->redisProxyManager as $proxy) {
                    $proxy->check();
                }
            }
        });
    }
988615
function handleWorkerRestart(worker, code, signal) {
		delete self.workers[worker.id];
		if (self.reviveWorkers) {
			var zombie = cluster.fork({
				config: JSON.stringify(self.config)
			});
			self.workers[zombie.id] = zombie;
		}
	}