Swoole\Client->connect

Declaration

<?php
Swoole\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
if ($cli->connect('127.0.0.1', 9501)) {
    $cli->send("data");
} else {
    echo "connect failed.";
}