for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of json-rpc-client.
*
* (c) Igor Lazarev <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Strider2038\JsonRpcClient\Transport\Socket;
use Strider2038\JsonRpcClient\Exception\ConnectionFailedException;
/**
* @author Igor Lazarev <[email protected]>
class SocketConnector
{
* @throws ConnectionFailedException
public function open(string $url, int $connectionTimeoutUs, int $requestTimeoutUs): SocketConnection
$errorCode = null;
$errorDescription = null;
$stream = @stream_socket_client($url, $errorCode, $errorDescription, (float) $connectionTimeoutUs / 1000000);
if (!is_resource($stream)) {
throw new ConnectionFailedException($url, sprintf('%d: %s', $errorCode, $errorDescription));
}
if (false === stream_set_timeout($stream, 0, $requestTimeoutUs)) {
throw new ConnectionFailedException($url, 'failed to set request timeout');
return new SocketConnection($stream, $url, $requestTimeoutUs);
public function wait(int $us): void
usleep($us);