Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F 修复可能导致网关进程退出的问题 #898

Open
wants to merge 1 commit into
base: 4.0
Choose a base branch
from

Conversation

xiasf
Copy link

@xiasf xiasf commented Mar 29, 2023

修复 gateway-worker 项目中 Gateway::closeClient($client_id, (array) $message); 会导致 网关进程报错退出的问题:

2023-03-08 17:50:28 pid:19154 Workerman[/home/myweb/spug_repos/gatewayworker_test/23_20230308175027/Applications/AdvertApp/start_g.php] already running

2023-03-09 10:46:19 pid:1361 Exception: You can't send(array) to client, you need to convert it to a string.  in /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Protocols/Websocket.php:230


Stack trace:
#0 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Connection/TcpConnection.php(321): Workerman\Protocols\Websocket::encode(Array, Object(Workerman\Connection\TcpConnection))
#1 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Connection/TcpConnection.php(821): Workerman\Connection\TcpConnection->send(Array, false)
#2 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/gateway-worker/src/Gateway.php(603): Workerman\Connection\TcpConnection->close(Array)
#3 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Connection/TcpConnection.php(638): GatewayWorker\Gateway->onWorkerMessage(Object(Workerman\Connection\TcpConnection), Array)
#4 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Events/Select.php(295): Workerman\Connection\TcpConnection->baseRead(Resource id #11674178)
#5 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php(2465): Workerman\Events\Select->loop()
#6 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/gateway-worker/src/Gateway.php(287): Workerman\Worker->run()
#7 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php(1574): GatewayWorker\Gateway->run()
#8 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php(1416): Workerman\Worker::forkOneWorkerForLinux(Object(GatewayWorker\Gateway))
#9 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php(1390): Workerman\Worker::forkWorkersForLinux()
#10 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php(1722): Workerman\Worker::forkWorkers()
#11 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php(1660): Workerman\Worker::monitorWorkersForLinux()
#12 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php(559): Workerman\Worker::monitorWorkers()
#13 /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/Applications/AdvertApp/start_g.php(99): Workerman\Worker::runAll()
#14 {main}




2023-03-09 10:46:19 pid:607 worker[AdvertApp-gateway:1361] exit with status 64000
2023-03-09 10:46:19 pid:20899 Worker[20899] process terminated with ERROR: E_ERROR "Uncaught Error: Class '\Workerman\Events\Select' not found in /home/myweb/spug_repos/gatewayworker_test/23_20230302113526/vendor/workerman/workerman/Worker.php:2432

修复 gateway-worker 项目中 Gateway::closeClient($client_id, (array) $message); 会导致 网关进程报错退出的问题
@twomiao
Copy link
Contributor

twomiao commented Oct 5, 2023

$buffer = (string) $buffer;

这样强制转换发送给客户端不太好。
举个例子:
$buffer = [
'sss', 'aaa'
];

$connection->send((string)$buffer));
输出是 "array " 字符串,php不知道如何解析,最终你把array 字符串推送给ws客户端了。
你可以选择return,不做任何处理丢弃这次数据(本身数据就不太合法)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants