Closed Lany-w closed 1 year ago
class LaramanWorker extends Worker
{
/**
* 去掉了默认的resetStd()
* @throws Exception
*/
public static function RunAll(): void
{
static::lock();
static::daemonize();
static::initWorkers();
static::installSignal();
static::saveMasterPid();
static::lock(\LOCK_UN);
static::displayUI();
//static::forkWorkers();
//static::resetStd();
static::monitorWorkers();
}
static::forkWorkers这个方法引起的问题,但是我看webman里也调用了Worker的这个方法,是可以正常启动的, 我注释掉这个方法可以正常启动了,但是请求响应很慢很慢
我应该是找到问题了. webman在runAll之前有过这个动作
$worker = new Worker($config['listen'], $config['context']);
这是Worker的构造方法
public function __construct($socket_name = '', array $context_option = array())
{
// Save all worker instances.
$this->workerId = \spl_object_hash($this);
static::$_workers[$this->workerId] = $this;
laraman好像没有实例化Worker的动作,static::$_workers
也就是空的, 导致initId
这个方法是不会给 static::$_idMap
赋值
protected static function initId()
{
foreach (static::$_workers as $worker_id => $worker) {
$new_id_map = array();
$worker->count = $worker->count < 1 ? 1 : $worker->count;
for($key = 0; $key < $worker->count; $key++) {
$new_id_map[$key] = isset(static::$_idMap[$worker_id][$key]) ? static::$_idMap[$worker_id][$key] : 0;
}
static::$_idMap[$worker_id] = $new_id_map;
}
}
所以这里就出问题了
protected static function forkOneWorkerForLinux(self $worker)
{
// Get available worker id.
$id = static::getId($worker->workerId, 0);
protected static function getId($worker_id, $pid)
{
return \array_search($pid, static::$_idMap[$worker_id]);
}
修复了一系列问题请使用v2.0.6
不是start.php 启动参数那里的问题