Swoole\Coroutine\Client->connect

Declaration

<?php
Swoole\Coroutine\Client->connect(string $host, int $port = null, float $timeout = 0.1, int $sock_flag = null)

Parameters

host

Host name or IP of the remote server

port

Port of the remote server

timeout

The timeout(second) of connect/send/recv, the dafault value is 0.1 second

sock_flag

Host name or IP of the remote server

Return

Description

Establish the connection.

Example

<?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();