1 | <?php |
||
5 | class PortTester |
||
6 | { |
||
7 | |||
8 | const BACKEND_STREAM_SOCKET = 'stream_socket'; |
||
9 | const BACKEND_SOCKET_CREATE = 'socket_create'; |
||
10 | const BACKEND_PFSOCKOPEN = 'pfsockopen'; |
||
11 | const BACKEND_CURL = 'curl'; |
||
12 | |||
13 | |||
14 | const PROTOCOL_TCP = 'tcp'; |
||
15 | const PROTOCOL_UDP = 'udp'; |
||
16 | const PROTOCOL_HTTP = 'http'; |
||
17 | const PROTOCOL_HTTPS = 'https'; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $supportedBackends = array('stream_socket', 'socket_create', 'pfsockopen', 'curl'); |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $supportedProtocols = array('tcp', 'udp', 'http', 'https'); |
||
28 | |||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $defaults = array( |
||
34 | 'backend' => null, |
||
35 | 'timeout' => 1, |
||
36 | 'close_timeout_ms' => null |
||
37 | ); |
||
38 | |||
39 | |||
40 | /** |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $options; |
||
45 | |||
46 | /** |
||
47 | * Constructor |
||
48 | * |
||
49 | * <code> |
||
50 | * $options = [ |
||
51 | * 'backend' => PortTester::BACKEND_STREAM_SOCKET, |
||
52 | * // connection timeout in seconds |
||
53 | * 'timeout' => 1, |
||
54 | * // timeout to wait for connection to be closed |
||
55 | * // properly in milliseconds or null to disable |
||
56 | * // Use when TIME_WAIT is too long |
||
57 | * 'close_timeout_ms => 300 |
||
58 | * ]; |
||
59 | * $portTester = new PortTester($options); |
||
60 | * </code> |
||
61 | * |
||
62 | * @throws \InvalidArgumentException |
||
63 | * @param array $options |
||
64 | */ |
||
65 | 5 | public function __construct($options = array()) |
|
79 | |||
80 | /** |
||
81 | * Check if TCP port is available for binding |
||
82 | * |
||
83 | * @throws \InvalidArgumentException |
||
84 | * @throws \RuntimeException |
||
85 | * |
||
86 | * @param string $host |
||
87 | * @param int $port |
||
88 | * @param string $protocol |
||
89 | * @param int|null $timeout |
||
90 | * @return boolean |
||
91 | */ |
||
92 | 3 | public function isAvailable($host, $port, $protocol = 'http', $timeout = null) |
|
179 | |||
180 | |||
181 | /** |
||
182 | * Test whether curl extension is available |
||
183 | * @return boolean |
||
184 | */ |
||
185 | 3 | protected function isCurlAvailable() |
|
189 | } |
||
190 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.