<?php
Swoole\Coroutine\Client->connect(string $host, int $port = null, float $timeout = 0.1, int $sock_flag = null)
Host name or IP of the remote server
Port of the remote server
The timeout(second) of connect/send/recv, the dafault value is 0.1 second
Host name or IP of the remote server
Establish the connection.
<?php
$client = new Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
if (!$client->connect('127.0.0.1', 9501, 0.5))
{
exit("connect failed. Error: {$client->errCode}\n");
}
$client->send("hello world\n");
echo $client->recv();
$client->close();