Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit a3520b6

Browse files
committed
🐛 修复socket.io循环问题
1 parent df7fee9 commit a3520b6

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

inc/socketio.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function connect() {
2626
}
2727

2828
while(true) {
29-
$alldata = $client->recv();
29+
$alldata = $client->recv(1);
3030
if (!is_bool($alldata)){
3131
$this->data = $data = $alldata->data;
3232
preg_match('/^\d+/', $data, $code);
@@ -76,7 +76,7 @@ public function connect() {
7676
});
7777
}
7878
elseif (isset($jsondata[0][1]) && $jsondata[0][1] == "0"){
79-
mlog("[socket.io]主控返回节点已掉线");
79+
mlog("[socket.io]节点已掉线");
8080
global $pid;
8181
posix_kill($pid, SIGINT);
8282
}
@@ -86,6 +86,11 @@ public function connect() {
8686
}
8787
elseif (isset($jsondata[0][0]["message"])){
8888
mlog("[socket.io]Got data {$jsondata[0][0]["message"]}");
89+
if (strpos($jsondata[0][0]["message"], "Error") !== false) {
90+
mlog("[socket.io]节点启用失败");
91+
global $pid;
92+
posix_kill($pid, SIGINT);
93+
}
8994
}
9095
else {
9196
mlog("[socket.io]Got data {$data}");
@@ -94,14 +99,22 @@ public function connect() {
9499
}
95100
if ($code[0] == '423'){
96101
$data = substr($data, strlen($code[0]));
97-
mlog("[socket.io]Got data {$data}");
102+
if(isset($jsondata[0][0]["message"])){
103+
mlog("[socket.io]Got data {$jsondata[0][0]["message"]}");
104+
}
105+
else{
106+
mlog("[socket.io]Got data {$data}");
107+
}
98108
}
99109
//var_dump($data);
100110
}
101111
global $shouldExit;
102112
global $httpserver;
103113
if ($shouldExit) {
104-
Swoole\Timer::clear($katimeid);
114+
global $enable;
115+
if($enable){
116+
Swoole\Timer::clear($katimeid);
117+
}
105118
$this->disable();
106119
$httpserver->stopserver();
107120
return;

0 commit comments

Comments
 (0)