在webman中使用unix协议时如何自定义通讯协议?
我看官方文档中自定义通讯协议都是基于TCP的。
<?php
return [
'user-service' => [
// 这里指定进程类
'handler' => \LinFly\JsonRpc\Handler::class,
// 监听的协议 ip 及端口
'listen' => 'JsonRpc:///tmp/user-service',
// 进程数 (可选,默认1)
'count' => 1,
// 当前进程是否支持reload (可选,默认true)
'reloadable' => true,
// 是否开启reusePort (可选,此选项需要php>=7.0,默认为true)
'reusePort' => true,
// transport (可选,当需要开启ssl时设置为ssl,默认为tcp)
'transport' => 'tcp',
// context (可选,当transport为是ssl时,需要传递证书路径)
'context' => [],
// 进程类构造函数参数,这里为 handler 类的构造函数参数 (可选)
'constructor' => ['user-service'],
],
];
上面的配置使用了自定义的JsonRpc通讯协议和unix地址,运行程序时抛出以下错误:
bash-5.1# php start.php start
Workerman[start.php] start in DEBUG mode
--------------------------------------------- WORKERMAN ---------------------------------------------
Workerman version:4.1.5 PHP version:8.0.21 Event-Loop:\Workerman\Events\Select
---------------------------------------------- WORKERS ----------------------------------------------
proto user worker listen processes status
tcp root user-service jsonRpc:///tmp/user-service 1 [OK]
-----------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
stream_socket_server(): Unable to connect to tcp:///tmp/user-service (Failed to parse address "/tmp/user-service") in file /project/microservice-mall/user-service/vendor/workerman/workerman/Worker.php on line 2294
PHP Fatal error: Uncaught Exception: Failed to parse address "/tmp/user-service" in /project/microservice-mall/user-service/vendor/workerman/workerman/Worker.php:2296
Stack trace:
#0 /project/microservice-mall/user-service/vendor/workerman/workerman/Worker.php(1561): Workerman\Worker->listen()
#1 /project/microservice-mall/user-service/vendor/workerman/workerman/Worker.php(1420): Workerman\Worker::forkOneWorkerForLinux()
#2 /project/microservice-mall/user-service/vendor/workerman/workerman/Worker.php(1394): Workerman\Worker::forkWorkersForLinux()
#3 /project/microservice-mall/user-service/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers()
#4 /project/microservice-mall/user-service/vendor/workerman/webman-framework/src/support/App.php(124): Workerman\Worker::runAll()
#5 /project/microservice-mall/user-service/start.php(4): support\App::run()
#6 {main}
thrown in /project/microservice-mall/user-service/vendor/workerman/workerman/Worker.php on line 2296
类似这样
可以了,谢谢老大