Skip to content

Commit b4d34cd

Browse files
committed
use Swoole\Coroutine\Client
1 parent 6d7d6f5 commit b4d34cd

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

src/HttpServer.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,22 @@ public function getStatus(): string {
166166
}
167167
public function talk(array $cmds, string $host = '127.0.0.1', ?int $port = null): void {
168168
echo $this->getStatus();
169-
$client = new \Swoole\Client(SWOOLE_SOCK_TCP);
170-
$client->set(
171-
[
172-
'open_eof_check' => true,
173-
'package_eof' => "\r\n",
174-
'package_max_length' => 1024 * 1024 * 2
175-
]);
176-
if (! $client->connect($host, $port ?? Environment::getServiceConfig()->terminal_server_port, - 1))
177-
exit("connect failed. Error: {$client->errCode}\n");
178-
$client->send(\Swoole\Serialize::pack($cmds, SWOOLE_FAST_PACK) . "\r\n");
179-
for($response = $client->recv(); $response !== '' && $response !== false; $response = $client->recv())
180-
echo $response;
181-
$client->close();
169+
go(
170+
function () use ($cmds, $host, $port) {
171+
$client = new \Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
172+
$client->set(
173+
[
174+
'open_eof_check' => true,
175+
'package_eof' => "\r\n",
176+
'package_max_length' => 1024 * 1024 * 2
177+
]);
178+
if (! $client->connect($host, $port ?? Environment::getServiceConfig()->terminal_server_port, - 1))
179+
exit("connect failed. Error: {$client->errCode}\n");
180+
$client->send(\Swoole\Serialize::pack($cmds, SWOOLE_FAST_PACK) . "\r\n");
181+
for($response = $client->recv(); $response; $response = $client->recv())
182+
echo $response;
183+
$client->close();
184+
});
182185
}
183186
public function onStart(\Swoole\Server $server): void {
184187
@cli_set_process_title(Environment::getName() . ' master');

0 commit comments

Comments
 (0)