'protocol' => Frame::class
我在 \Channel\Server::onMessage 方法里面进行打印
1 使用端口的方式,正常没报错
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 方式报错
plugin.webman.channel.server unix:///tmp/channel-1735198572.sock
打印如下 数据好像合并成一条
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";}}"
导致unserialize方法报错
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)
{
// 插件进程不订阅
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("//", $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"
},
系统 wsl 的ubuntu
Workerman version:4.2.1
PHP version:8.1.26
Event-Loop:\Workerman\Events\Event
执行composer info 看下 workerman/channel 具体版本
webman/channel 1.0.1
workerman/channel 1.2.1
config/plugin/webman/channel/process.php 指定下协议试下
正常了,谢谢老大