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