'protocol' => Frame::class
我在 \Channel\Server::onMessage 方法里面進(jìn)行打印
1 使用端口的方式,正常沒(méi)報(bào)錯(cuò)
plugin.webman.channel.server frame://0.0.0.0:2206
打印如下
string(83) "a:2:{s:4:"type";s:9:"subscribe";s:8:"channels";a:1:{i:0;s:17:"crontab-task-edit";}}"
string(83) "a:2:{s:4:"type";s:9:"subscribe";s:8:"channels";a:1:{i:0;s:17:"crontab-task-edit";}}"
2 使用unix 方式報(bào)錯(cuò)
plugin.webman.channel.server unix:///tmp/channel-1735198572.sock
打印如下 數(shù)據(jù)好像合并成一條
string(174) "Wa:2:{s:4:"type";s:9:"subscribe";s:8:"channels";a:1:{i:0;s:17:"crontab-task-edit";}}Wa:2:{s:4:"type";s:9:"subscribe";s:8:"channels";a:1:{i:0;s:17:"crontab-task-edit";}}"
導(dǎo)致unserialize方法報(bào)錯(cuò)
1 鏈接
<?php
namespace app\bootstrap;
use support\Log;
use Webman\Bootstrap;
use Webman\Channel\Client;
use Workerman\Worker;
class Channel implements Bootstrap
{
public static function start(?Worker $worker)
{
// 插件進(jìn)程不訂閱
if (!$worker || $worker->name == 'plugin.webman.channel.server') {
return;
}
try {
$app_config = config('plugin.webman.channel.app');
if ($app_config['enable']) {
$process_config = config('plugin.webman.channel.process');
$listen = (string)$process_config['server']['listen'];
$listen = trim($listen);
if (stripos($listen, 'unix://') === 0) {
Client::connect($listen);
} else {
[, $ip_info] = explode("http://", $listen, 2);
[$ip, $port] = explode(":", trim($ip_info), 2);
Client::connect($ip, $port);
}
}
} catch (\Exception $e) {
Log::error("Bootstrap的Channel " . $e->getMessage());
}
}
}
2 訂閱
<?php
namespace app\process;
use Webman\Channel\Client;
use Workerman\Worker;
class CrontabTaskProducer
{
public function onWorkerStart(Worker $worker)
{
Client::on("crontab-task-edit", function ($event_data) {
var_dump($event_data);
});
}
}
3 composer.json
"require": {
"php": ">=8.0",
"workerman/webman-framework": "^1.6.8",
"monolog/monolog": "^2.0",
"webman/channel": "^1.0"
},
系統(tǒng) wsl 的ubuntu
Workerman version:4.2.1
PHP version:8.1.26
Event-Loop:\Workerman\Events\Event
執(zhí)行composer info 看下 workerman/channel 具體版本
config/plugin/webman/channel/process.php 指定下協(xié)議試下
use Webman\Channel\Server;
use Workerman\Protocols\Frame;
return [
'server' => [
'listen' => 'unix:///tmp/channel-1735198572.sock',
'protocol' => Frame::class, // 這里指定協(xié)議
'handler' => Server::class,
'reloadable' => false,
'count' => 1
]
];