Total Complexity | 4 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Coverage | 63.64% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | class SocketConnector |
||
21 | { |
||
22 | /** |
||
23 | * @throws ConnectionFailedException |
||
24 | */ |
||
25 | 5 | public function open(string $url, int $connectionTimeoutUs, int $requestTimeoutUs): SocketConnection |
|
26 | { |
||
27 | 5 | $errorCode = null; |
|
28 | 5 | $errorDescription = null; |
|
29 | |||
30 | 5 | $stream = @stream_socket_client($url, $errorCode, $errorDescription, (float) $connectionTimeoutUs / 1000000); |
|
31 | |||
32 | 5 | if (!is_resource($stream)) { |
|
33 | throw new ConnectionFailedException($url, sprintf('%d: %s', $errorCode, $errorDescription)); |
||
34 | } |
||
35 | |||
36 | 5 | if (false === stream_set_timeout($stream, 0, $requestTimeoutUs)) { |
|
37 | throw new ConnectionFailedException($url, 'failed to set request timeout'); |
||
38 | } |
||
39 | |||
40 | 5 | return new SocketConnection($stream, $url, $requestTimeoutUs); |
|
41 | } |
||
42 | |||
43 | public function wait(int $us): void |
||
46 | } |
||
47 | } |
||
48 |