GatewayWorker 路由 route 中 返回值 为 false 不可以吗?

casper13

手册中写的是

返回值
返回 $worker_connnections 中的一个连接对象。如果没有可返回的$worker_connnections,则返回false。

然后我这样写return false;

最终报错了竟然

PHP Fatal error:  Call to a member function send() on boolean in /share/gatewayworker/vendor/workerman/gateway-worker/src/Gateway.php on line 414

Fatal error: Call to a member function send() on boolean in /share/gatewayworker/vendor/workerman/gateway-worker/src/Gateway.php on line 414

Worker[21969] process terminated with ERROR: E_ERROR "Call to a member function send() on boolean in /share/gatewayworker/vendor/workerman/gateway-worker/src/Gateway.php on line 414"

看了源码好像是没有对返回的worker_connection错判断

$worker_connection = call_user_func($this->router, $this->_workerConnections, $connection, $cmd, $body);
if (false === $worker_connection->send($gateway_data)) {
     $msg = "SendBufferToWorker fail. May be the send buffer are overflow. See http://doc2.workerman.net/send-buffer-overflow.html";
     static::log($msg);
     return false;
}
743 1 0
1个回答

walkor 打赏

必须返回一个连接对象

  • casper13 2023-06-06

    那手册中写的 如果没有可返回的$worker_connnections,则返回false。该如何解释? 再者该如何返回一个默认连接对象?

  • casper13 2023-06-06

    实际场景,2个gateway监听不同类型协议的端口,想用这个路由功能导向不同的BusinessWorker中处理,但如何将无法分流的数导向默认BusinessWorker或者干脆干掉?

  • walkor 2023-06-06

    文档写错了,或者自己改下源码,判断下 $worker_connnection 是不是false

年代过于久远,无法发表回答
×
🔝