stream_socket_client

Supported Versions: PHP 5, PHP 7, PHP 8
Open Internet or Unix domain socket connection
<?php stream_socket_client(    string $address,    int &$error_code = null,    string &$error_message = null,    ?float $timeout = null,    int $flags = STREAM_CLIENT_CONNECT,    ?resource $context = null): resource|false
<?php $stream = stream_socket_client('tcp://www.google.com:80');

if (!$stream) {

    exit(1);

}
<?php $stream = stream_socket_client('tcp://' . $ip . ':80', $errno, $errstr, null, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);

if (!$stream) {

    exit(1);

}
<?php         $server = stream_socket_server('127.0.0.1:0');



        $errno = $errstr = null;

        $connecting = stream_socket_client(stream_socket_get_name($server, false), $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);



        $loop = $this->loop;

        $timeout = $loop->addTimer(0.1, function () use ($connecting, $loop) {
<?php         $errno = $errstr = null;

        if (@stream_socket_client('127.0.0.1:1', $errno, $errstr, 10.0) !== false || (defined('SOCKET_ECONNREFUSED') && $errno !== SOCKET_ECONNREFUSED)) {

            $this->markTestSkipped('Expected host to refuse connection, but got error ' . $errno . ': ' . $errstr);

        }
<?php             $this->markTestSkipped('Expected host to refuse connection, but got error ' . $errno . ': ' . $errstr);

        }



        $connecting = stream_socket_client('127.0.0.1:1', $errno, $errstr, 0, STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT);



        $loop = $this->loop;

        $timeout = $loop->addTimer(10.0, function () use ($connecting, $loop) {