1 | <?php |
||
5 | class Socket |
||
6 | { |
||
7 | /** |
||
8 | * Being fairly conservative here: |
||
9 | * |
||
10 | * Implementations of the IP protocol are not required to be capable of handling arbitrarily large packets. In |
||
11 | * theory, the maximum possible IP packet size is 65,535 octets, but the standard only requires that implementations |
||
12 | * support at least 576 octets. |
||
13 | * |
||
14 | * via http://stackoverflow.com/a/3712822/10831 |
||
15 | * |
||
16 | * Over this limit, we'll just fragment at the application layer, and send more than one packet. |
||
17 | */ |
||
18 | const MAX_DATAGRAM_SIZE = 500; |
||
19 | |||
20 | protected $host; |
||
21 | protected $port; |
||
22 | protected $socket = null; |
||
23 | |||
24 | /** |
||
25 | * Socket constructor |
||
26 | * |
||
27 | * @param string $host |
||
28 | * @param int $port |
||
29 | */ |
||
30 | 4 | public function __construct($host = '127.0.0.1', $port = 8125) |
|
36 | |||
37 | /** |
||
38 | * @return void |
||
39 | */ |
||
40 | 2 | public function open() |
|
44 | |||
45 | /** |
||
46 | * @param string $data |
||
47 | * @return int|null Number of bytes written |
||
|
|||
48 | */ |
||
49 | 2 | public function write($data) |
|
57 | |||
58 | /** |
||
59 | * Closes the socket |
||
60 | */ |
||
61 | 2 | public function close() |
|
69 | } |
||
70 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.