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         $remote = 'tcp://' . $parts['host'] . ':' . $parts['port'];



        $stream = @\stream_socket_client(

            $remote,

            $errno,

            $errstr,

            0,

            \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT,

            \stream_context_create($context)

        );



        if (false === $stream) {

            return Promise\reject(new \RuntimeException(
<?php             ));

        }



        $resource = @\stream_socket_client($path, $errno, $errstr, 1.0);



        if (!$resource) {

            return Promise\reject(new \RuntimeException(
<?php         $socket = stream_socket_server('tcp://127.0.0.1:0');



        $fd = self::getNextFreeFd();

        $client = stream_socket_client('tcp://' . stream_socket_get_name($socket, false));

        assert($client !== false);



        $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
<?php         $socket = stream_socket_server('127.0.0.1:0');

        assert($socket !== false);



        $client = stream_socket_client('tcp://' . stream_socket_get_name($socket, false));



        $server = new FdServer($fd);

        $promise = new Promise(function ($resolve) use ($server) {
<?php         Loop::addReadStream($socket, function ($socket) use (&$received) {

            $request = stream_socket_recvfrom($socket, 65536, 0, $peer);



            $client = stream_socket_client('udp://8.8.8.8:53');

            fwrite($client, $request);

            $response = fread($client, 65536);
<?php     {

        $tcp = new TcpServer(0);



        $socket = stream_socket_client($tcp->getAddress());

        fclose($socket);



        $server = new LimitingServer($tcp, 100);
<?php             $server->on('connection', $resolve);

        });



        $first = stream_socket_client($server->getAddress());

        $second = stream_socket_client($server->getAddress());



        Block\await($peer, null, self::TIMEOUT);
<?php         });



        $first = stream_socket_client($server->getAddress());

        $second = stream_socket_client($server->getAddress());



        Block\await($peer, null, self::TIMEOUT);
<?php             });

        });



        $first = stream_socket_client($server->getAddress());

        fclose($first);

        $second = stream_socket_client($server->getAddress());

        fclose($second);
<?php         $first = stream_socket_client($server->getAddress());

        fclose($first);

        $second = stream_socket_client($server->getAddress());

        fclose($second);



        Block\await($peer, null, self::TIMEOUT);
<?php             $server->on('connection', $resolve);

        });



        $client = stream_socket_client($server->getAddress());



        Block\await($peer, null, self::TIMEOUT);
<?php         $server->pause();

        $server->on('connection', $this->expectCallableNever());



        $client = stream_socket_client($server->getAddress());



        Block\sleep(0.1, null);

    }
<?php             $server->on('connection', $resolve);

        });



        $client = stream_socket_client($server->getAddress());



        $server->resume();
<?php         $address = $server->getAddress();

        $server->close();



        $client = @stream_socket_client($address);



        $this->assertFalse($client);

    }
<?php         });





        $client = stream_socket_client($server->getAddress());



        $all = Block\await($peer, null, self::TIMEOUT);