1.我是基于thinkphp6 然后在config目錄里的worker_server.php文件 設(shè)置了worker_class屬性為數(shù)組,兩個(gè)worker服務(wù),但是當(dāng)我在命令行 啟動(dòng)worker:server 的時(shí)候 就只能啟動(dòng)數(shù)組第一個(gè)服務(wù) 第二個(gè)沒(méi)有提示,是我的理解有問(wèn)題還是業(yè)務(wù)上不能這么處理?
PS:我的業(yè)務(wù)邏輯是:創(chuàng)建不同的worker webscoket 端口 然后處理不同的業(yè)務(wù),端口2345 處理 業(yè)務(wù)A,端口2346處理業(yè)務(wù)B。所以我設(shè)置了worker_class的數(shù)組屬性
然后通過(guò)chatGPT的提示說(shuō)是第一個(gè)worker把第二個(gè)阻塞了?不太理解這個(gè)解釋
業(yè)務(wù)A:文件workera.php
public function __construct() {
//實(shí)例化 WebSocket 服務(wù)
$this->worker = new WorkerMan($this->socket);
$type = Config::get('cache.default');
$this->cachePrefix = Config::get('cache.stores')[$type]['prefix'];
$this->workerManStartLock = $this->cachePrefix . Config::get('cache_option.prefix')['workerman_start_lock'];
//系統(tǒng)類(lèi)型
$this->systemType = env('sign.system_type');
$this->config = Config::get('rabbitmq')['channel'][$this->systemType];
$this->setting = Setting::getItem("trade");
//初始化
if (!$this->init()) {
return false;
}
//設(shè)置回調(diào)
foreach (['onWorkerStart', 'onConnect', 'onMessage', 'onClose', 'onError', 'onBufferFull', 'onBufferDrain', 'onWorkerStop', 'onWorkerReload'] as $event) {
if (method_exists($this, $event)) {
$this->worker->$event = [$this, $event];
}
}
//Run worker
WorkerMan::runAll();
}
public function init(): bool
{
$this->processes = count($this->config);//3個(gè)
$multiple = env('sign.multiple');
$pidPath = env('runtime_path') .'/worker/.run/';
$logPath = runtime_path() .'/worker/log/';
!is_dir($logPath) && mkdir($logPath, 0755, true);
!is_dir($pidPath) && mkdir($pidPath, 0755, true);
$this->redis = Cache::store('redis')->handler();
$this->worker->count = $this->processes * $multiple; //18
$this->worker->name = 'recharge';
WorkerMan::$daemonize = true;
WorkerMan::$logFile = $logPath . 'workerman.log';
WorkerMan::$stdoutFile = $logPath . 'workerman_stdout.log';
WorkerMan::$pidFile = $pidPath . 'workerman.pid';
return true;
}
業(yè)務(wù)B:workerb.php
public function __construct()
{
$this->worker = new Worker($this->socket);
$this->cliCmd = $_SERVER['argv'][1];
//設(shè)置緩存前綴
$type = Config::get('cache.default');
$this->cachePrefix = Config::get('cache.stores')[$type]['prefix'];
//設(shè)置控制多進(jìn)程啟動(dòng)的鎖對(duì)象
$this->workerManStartLock = $this->cachePrefix . Config::get('cache_option.prefix')['workerman_start_lock'];
//系統(tǒng)類(lèi)型
$this->systemType =env('jd_sign.machine');
$this->config = Config::get('rabbitmq')['jd_channel'][$this->systemType];
//初始化
if (!$this->init()) {
return false;
}
//設(shè)置回調(diào)
foreach (['onWorkerStart', 'onConnect', 'onMessage', 'onClose', 'onError', 'onBufferFull', 'onBufferDrain', 'onWorkerStop', 'onWorkerReload'] as $event) {
if (method_exists($this, $event)) {
$this->worker->$event = [$this, $event];
}
}
//Run worker
Worker::runAll();
}
private function init(): bool
{
$this->processes = count($this->config);//3進(jìn)程:BIND_JD_BIG、CHECK_JD_TEMP、CHECK_JD
$multiple = env('jd_sign.multiple');
//創(chuàng)建日志目錄
$pidPath = env('jd_runtime_path.path') .'/worker/.run/';
$logPath = env('jd_runtime_path.path') . '/log/';
!is_dir($logPath) && mkdir($logPath, 0755, true);
!is_dir($pidPath) && mkdir($pidPath, 0755, true);
$this->worker->count = $this->processes * $multiple; // 一個(gè)加急進(jìn)程 multiple = 7 count = 3*7
$this->worker->name = 'jdrecharge';
Worker::$daemonize = true;
Worker::$logFile = $logPath . 'workerman.log';
Worker::$stdoutFile = $logPath . 'workerman_stdout.log';
Worker::$pidFile = $pidPath . 'workerman.pid';
return true;
}