-
Notifications
You must be signed in to change notification settings - Fork 8
/
sockets.php
2000 lines (1862 loc) · 54.9 KB
/
sockets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// Start of sockets v.7.0.4-7ubuntu2
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Runs the select() system call on the given arrays of sockets with a specified timeout
* @link http://php.net/manual/en/function.socket-select.php
* @param array $read <p>
* The sockets listed in the <i>read</i> array will be
* watched to see if characters become available for reading (more
* precisely, to see if a read will not block - in particular, a socket
* resource is also ready on end-of-file, in which case a
* <b>socket_read</b> will return a zero length string).
* </p>
* @param array $write <p>
* The sockets listed in the <i>write</i> array will be
* watched to see if a write will not block.
* </p>
* @param array $except <p>
* The sockets listed in the <i>except</i> array will be
* watched for exceptions.
* </p>
* @param int $tv_sec <p>
* The <i>tv_sec</i> and <i>tv_usec</i>
* together form the timeout parameter. The
* timeout is an upper bound on the amount of time
* elapsed before <b>socket_select</b> return.
* <i>tv_sec</i> may be zero , causing
* <b>socket_select</b> to return immediately. This is useful
* for polling. If <i>tv_sec</i> is <b>NULL</b> (no timeout),
* <b>socket_select</b> can block indefinitely.
* </p>
* @param int $tv_usec [optional]
* @return int On success <b>socket_select</b> returns the number of
* socket resources contained in the modified arrays, which may be zero if
* the timeout expires before anything interesting happens. On error <b>FALSE</b>
* is returned. The error code can be retrieved with
* <b>socket_last_error</b>.
* </p>
* <p>
* Be sure to use the === operator when checking for an
* error. Since the <b>socket_select</b> may return 0 the
* comparison with == would evaluate to <b>TRUE</b>:
* Understanding <b>socket_select</b>'s result
* <code>
* $e = NULL;
* if (false === socket_select($r, $w, $e, 0)) {
* echo "socket_select() failed, reason: " .
* socket_strerror(socket_last_error()) . "\n";
* }
* </code>
*/
function socket_select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0): int {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Create a socket (endpoint for communication)
* @link http://php.net/manual/en/function.socket-create.php
* @param int $domain <p>
* The <i>domain</i> parameter specifies the protocol
* family to be used by the socket.
* </p>
* <table>
* Available address/protocol families
* <tr valign="top">
* <td>Domain</td>
* <td>Description</td>
* </tr>
* <tr valign="top">
* <td><b>AF_INET</b></td>
* <td>
* IPv4 Internet based protocols. TCP and UDP are common protocols of
* this protocol family.
* </td>
* </tr>
* <tr valign="top">
* <td><b>AF_INET6</b></td>
* <td>
* IPv6 Internet based protocols. TCP and UDP are common protocols of
* this protocol family.
* </td>
* </tr>
* <tr valign="top">
* <td><b>AF_UNIX</b></td>
* <td>
* Local communication protocol family. High efficiency and low
* overhead make it a great form of IPC (Interprocess Communication).
* </td>
* </tr>
* </table>
* @param int $type <p>
* The <i>type</i> parameter selects the type of communication
* to be used by the socket.
* </p>
* <table>
* Available socket types
* <tr valign="top">
* <td>Type</td>
* <td>Description</td>
* </tr>
* <tr valign="top">
* <td><b>SOCK_STREAM</b></td>
* <td>
* Provides sequenced, reliable, full-duplex, connection-based byte streams.
* An out-of-band data transmission mechanism may be supported.
* The TCP protocol is based on this socket type.
* </td>
* </tr>
* <tr valign="top">
* <td><b>SOCK_DGRAM</b></td>
* <td>
* Supports datagrams (connectionless, unreliable messages of a fixed maximum length).
* The UDP protocol is based on this socket type.
* </td>
* </tr>
* <tr valign="top">
* <td><b>SOCK_SEQPACKET</b></td>
* <td>
* Provides a sequenced, reliable, two-way connection-based data transmission path for
* datagrams of fixed maximum length; a consumer is required to read an
* entire packet with each read call.
* </td>
* </tr>
* <tr valign="top">
* <td><b>SOCK_RAW</b></td>
* <td>
* Provides raw network protocol access. This special type of socket
* can be used to manually construct any type of protocol. A common use
* for this socket type is to perform ICMP requests (like ping).
* </td>
* </tr>
* <tr valign="top">
* <td><b>SOCK_RDM</b></td>
* <td>
* Provides a reliable datagram layer that does not guarantee ordering.
* This is most likely not implemented on your operating system.
* </td>
* </tr>
* </table>
* @param int $protocol <p>
* The <i>protocol</i> parameter sets the specific
* protocol within the specified <i>domain</i> to be used
* when communicating on the returned socket. The proper value can be
* retrieved by name by using <b>getprotobyname</b>. If
* the desired protocol is TCP, or UDP the corresponding constants
* <b>SOL_TCP</b>, and <b>SOL_UDP</b>
* can also be used.
* </p>
* <table>
* Common protocols
* <tr valign="top">
* <td>Name</td>
* <td>Description</td>
* </tr>
* <tr valign="top">
* <td>icmp</td>
* <td>
* The Internet Control Message Protocol is used primarily by gateways
* and hosts to report errors in datagram communication. The "ping"
* command (present in most modern operating systems) is an example
* application of ICMP.
* </td>
* </tr>
* <tr valign="top">
* <td>udp</td>
* <td>
* The User Datagram Protocol is a connectionless, unreliable,
* protocol with fixed record lengths. Due to these aspects, UDP
* requires a minimum amount of protocol overhead.
* </td>
* </tr>
* <tr valign="top">
* <td>tcp</td>
* <td>
* The Transmission Control Protocol is a reliable, connection based,
* stream oriented, full duplex protocol. TCP guarantees that all data packets
* will be received in the order in which they were sent. If any packet is somehow
* lost during communication, TCP will automatically retransmit the packet until
* the destination host acknowledges that packet. For reliability and performance
* reasons, the TCP implementation itself decides the appropriate octet boundaries
* of the underlying datagram communication layer. Therefore, TCP applications must
* allow for the possibility of partial record transmission.
* </td>
* </tr>
* </table>
* @return resource <b>socket_create</b> returns a socket resource on success,
* or <b>FALSE</b> on error. The actual error code can be retrieved by calling
* <b>socket_last_error</b>. This error code may be passed to
* <b>socket_strerror</b> to get a textual explanation of the
* error.
*/
function socket_create(int $domain, int $type, int $protocol) {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Opens a socket on port to accept connections
* @link http://php.net/manual/en/function.socket-create-listen.php
* @param int $port <p>
* The port on which to listen on all interfaces.
* </p>
* @param int $backlog [optional] <p>
* The <i>backlog</i> parameter defines the maximum length
* the queue of pending connections may grow to.
* <b>SOMAXCONN</b> may be passed as
* <i>backlog</i> parameter, see
* <b>socket_listen</b> for more information.
* </p>
* @return resource <b>socket_create_listen</b> returns a new socket resource
* on success or <b>FALSE</b> on error. The error code can be retrieved with
* <b>socket_last_error</b>. This code may be passed to
* <b>socket_strerror</b> to get a textual explanation of the
* error.
*/
function socket_create_listen(int $port, int $backlog = 128) {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Creates a pair of indistinguishable sockets and stores them in an array
* @link http://php.net/manual/en/function.socket-create-pair.php
* @param int $domain <p>
* The <i>domain</i> parameter specifies the protocol
* family to be used by the socket. See <b>socket_create</b>
* for the full list.
* </p>
* @param int $type <p>
* The <i>type</i> parameter selects the type of communication
* to be used by the socket. See <b>socket_create</b> for the
* full list.
* </p>
* @param int $protocol <p>
* The <i>protocol</i> parameter sets the specific
* protocol within the specified <i>domain</i> to be used
* when communicating on the returned socket. The proper value can be retrieved by
* name by using <b>getprotobyname</b>. If
* the desired protocol is TCP, or UDP the corresponding constants
* <b>SOL_TCP</b>, and <b>SOL_UDP</b>
* can also be used.
* </p>
* <p>
* See <b>socket_create</b> for the full list of supported
* protocols.
* </p>
* @param array $fd <p>
* Reference to an array in which the two socket resources will be inserted.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
function socket_create_pair(int $domain, int $type, int $protocol, array &$fd): bool {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Accepts a connection on a socket
* @link http://php.net/manual/en/function.socket-accept.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>.
* </p>
* @return resource a new socket resource on success, or <b>FALSE</b> on error. The actual
* error code can be retrieved by calling
* <b>socket_last_error</b>. This error code may be passed to
* <b>socket_strerror</b> to get a textual explanation of the
* error.
*/
function socket_accept($socket) {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Sets nonblocking mode for file descriptor fd
* @link http://php.net/manual/en/function.socket-set-nonblock.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
function socket_set_nonblock($socket): bool {}
/**
* (PHP 4 >= 4.2.0, PHP 5, PHP 7)<br/>
* Sets blocking mode on a socket resource
* @link http://php.net/manual/en/function.socket-set-block.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
*/
function socket_set_block($socket): bool {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Listens for a connection on a socket
* @link http://php.net/manual/en/function.socket-listen.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>.
* </p>
* @param int $backlog [optional] <p>
* A maximum of <i>backlog</i> incoming connections will be
* queued for processing. If a connection request arrives with the queue
* full the client may receive an error with an indication of
* ECONNREFUSED, or, if the underlying protocol supports
* retransmission, the request may be ignored so that retries may succeed.
* </p>
* <p>
* The maximum number passed to the <i>backlog</i>
* parameter highly depends on the underlying platform. On Linux, it is
* silently truncated to <b>SOMAXCONN</b>. On win32, if
* passed <b>SOMAXCONN</b>, the underlying service provider
* responsible for the socket will set the backlog to a maximum
* reasonable value. There is no standard provision to
* find out the actual backlog value on this platform.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure. The error code can be retrieved with
* <b>socket_last_error</b>. This code may be passed to
* <b>socket_strerror</b> to get a textual explanation of the
* error.
*/
function socket_listen($socket, int $backlog = 0): bool {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Closes a socket resource
* @link http://php.net/manual/en/function.socket-close.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @return void No value is returned.
*/
function socket_close($socket) {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Write to a socket
* @link http://php.net/manual/en/function.socket-write.php
* @param resource $socket
* @param string $buffer <p>
* The buffer to be written.
* </p>
* @param int $length [optional] <p>
* The optional parameter <i>length</i> can specify an
* alternate length of bytes written to the socket. If this length is
* greater than the buffer length, it is silently truncated to the length
* of the buffer.
* </p>
* @return int the number of bytes successfully written to the socket or <b>FALSE</b> on failure.
* The error code can be retrieved with
* <b>socket_last_error</b>. This code may be passed to
* <b>socket_strerror</b> to get a textual explanation of the
* error.
* </p>
* <p>
* It is perfectly valid for <b>socket_write</b> to
* return zero which means no bytes have been written. Be sure to use the
* === operator to check for <b>FALSE</b> in case of an
* error.
*/
function socket_write($socket, string $buffer, int $length = null): int {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Reads a maximum of length bytes from a socket
* @link http://php.net/manual/en/function.socket-read.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @param int $length <p>
* The maximum number of bytes read is specified by the
* <i>length</i> parameter. Otherwise you can use
* <b>\r</b>, <b>\n</b>,
* or <b>\0</b> to end reading (depending on the <i>type</i>
* parameter, see below).
* </p>
* @param int $type [optional] <p>
* Optional <i>type</i> parameter is a named constant:
* <b>PHP_BINARY_READ</b> (Default) - use the system
* recv() function. Safe for reading binary data.
* @return string <b>socket_read</b> returns the data as a string on success,
* or <b>FALSE</b> on error (including if the remote host has closed the
* connection). The error code can be retrieved with
* <b>socket_last_error</b>. This code may be passed to
* <b>socket_strerror</b> to get a textual representation of
* the error.
* </p>
* <p>
* <b>socket_read</b> returns a zero length string ("")
* when there is no more data to read.
*/
function socket_read($socket, int $length, int $type = PHP_BINARY_READ): string {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type
* @link http://php.net/manual/en/function.socket-getsockname.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @param string $addr <p>
* If the given socket is of type <b>AF_INET</b>
* or <b>AF_INET6</b>, <b>socket_getsockname</b>
* will return the local IP address in appropriate notation (e.g.
* 127.0.0.1 or fe80::1) in the
* <i>address</i> parameter and, if the optional
* <i>port</i> parameter is present, also the associated port.
* </p>
* <p>
* If the given socket is of type <b>AF_UNIX</b>,
* <b>socket_getsockname</b> will return the Unix filesystem
* path (e.g. /var/run/daemon.sock) in the
* <i>address</i> parameter.
* </p>
* @param int $port [optional] <p>
* If provided, this will hold the associated port.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure. <b>socket_getsockname</b> may also return
* <b>FALSE</b> if the socket type is not any of <b>AF_INET</b>,
* <b>AF_INET6</b>, or <b>AF_UNIX</b>, in which
* case the last socket error code is not updated.
*/
function socket_getsockname($socket, string &$addr, int &$port = null): bool {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type
* @link http://php.net/manual/en/function.socket-getpeername.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @param string $address <p>
* If the given socket is of type <b>AF_INET</b> or
* <b>AF_INET6</b>, <b>socket_getpeername</b>
* will return the peers (remote) IP address in
* appropriate notation (e.g. 127.0.0.1 or
* fe80::1) in the <i>address</i>
* parameter and, if the optional <i>port</i> parameter is
* present, also the associated port.
* </p>
* <p>
* If the given socket is of type <b>AF_UNIX</b>,
* <b>socket_getpeername</b> will return the Unix filesystem
* path (e.g. /var/run/daemon.sock) in the
* <i>address</i> parameter.
* </p>
* @param int $port [optional] <p>
* If given, this will hold the port associated to
* <i>address</i>.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure. <b>socket_getpeername</b> may also return
* <b>FALSE</b> if the socket type is not any of <b>AF_INET</b>,
* <b>AF_INET6</b>, or <b>AF_UNIX</b>, in which
* case the last socket error code is not updated.
*/
function socket_getpeername($socket, string &$address, int &$port = null): bool {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Initiates a connection on a socket
* @link http://php.net/manual/en/function.socket-connect.php
* @param resource $socket
* @param string $address <p>
* The <i>address</i> parameter is either an IPv4 address
* in dotted-quad notation (e.g. 127.0.0.1) if
* <i>socket</i> is <b>AF_INET</b>, a valid
* IPv6 address (e.g. ::1) if IPv6 support is enabled and
* <i>socket</i> is <b>AF_INET6</b>
* or the pathname of a Unix domain socket, if the socket family is
* <b>AF_UNIX</b>.
* </p>
* @param int $port [optional] <p>
* The <i>port</i> parameter is only used and is mandatory
* when connecting to an <b>AF_INET</b> or an
* <b>AF_INET6</b> socket, and designates
* the port on the remote host to which a connection should be made.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure. The error code can be retrieved with
* <b>socket_last_error</b>. This code may be passed to
* <b>socket_strerror</b> to get a textual explanation of the
* error.
* </p>
* <p>
* If the socket is non-blocking then this function returns <b>FALSE</b> with an
* error Operation now in progress.
*/
function socket_connect($socket, string $address, int $port = 0): bool {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Return a string describing a socket error
* @link http://php.net/manual/en/function.socket-strerror.php
* @param int $errno <p>
* A valid socket error number, likely produced by
* <b>socket_last_error</b>.
* </p>
* @return string the error message associated with the <i>errno</i>
* parameter.
*/
function socket_strerror(int $errno): string {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Binds a name to a socket
* @link http://php.net/manual/en/function.socket-bind.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>.
* </p>
* @param string $address <p>
* If the socket is of the <b>AF_INET</b> family, the
* <i>address</i> is an IP in dotted-quad notation
* (e.g. 127.0.0.1).
* </p>
* <p>
* If the socket is of the <b>AF_UNIX</b> family, the
* <i>address</i> is the path of a
* Unix-domain socket (e.g. /tmp/my.sock).
* </p>
* @param int $port [optional] <p>
* The <i>port</i> parameter is only used when
* binding an <b>AF_INET</b> socket, and designates
* the port on which to listen for connections.
* </p>
* @return bool <b>TRUE</b> on success or <b>FALSE</b> on failure.
* </p>
* <p>
* The error code can be retrieved with <b>socket_last_error</b>.
* This code may be passed to <b>socket_strerror</b> to get a
* textual explanation of the error.
*/
function socket_bind($socket, string $address, int $port = 0): bool {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Receives data from a connected socket
* @link http://php.net/manual/en/function.socket-recv.php
* @param resource $socket <p>
* The <i>socket</i> must be a socket resource previously
* created by socket_create().
* </p>
* @param string $buf <p>
* The data received will be fetched to the variable specified with
* <i>buf</i>. If an error occurs, if the
* connection is reset, or if no data is
* available, <i>buf</i> will be set to <b>NULL</b>.
* </p>
* @param int $len <p>
* Up to <i>len</i> bytes will be fetched from remote host.
* </p>
* @param int $flags <p>
* The value of <i>flags</i> can be any combination of
* the following flags, joined with the binary OR (|)
* operator.
* </p>
* <table>
* Possible values for <i>flags</i>
* <tr valign="top">
* <td>Flag</td>
* <td>Description</td>
* </tr>
* <tr valign="top">
* <td><b>MSG_OOB</b></td>
* <td>
* Process out-of-band data.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_PEEK</b></td>
* <td>
* Receive data from the beginning of the receive queue without
* removing it from the queue.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_WAITALL</b></td>
* <td>
* Block until at least <i>len</i> are received.
* However, if a signal is caught or the remote host disconnects, the
* function may return less data.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_DONTWAIT</b></td>
* <td>
* With this flag set, the function returns even if it would normally
* have blocked.
* </td>
* </tr>
* </table>
* @return int <b>socket_recv</b> returns the number of bytes received,
* or <b>FALSE</b> if there was an error. The actual error code can be retrieved by
* calling <b>socket_last_error</b>. This error code may be
* passed to <b>socket_strerror</b> to get a textual explanation
* of the error.
*/
function socket_recv($socket, string &$buf, int $len, int $flags): int {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Sends data to a connected socket
* @link http://php.net/manual/en/function.socket-send.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @param string $buf <p>
* A buffer containing the data that will be sent to the remote host.
* </p>
* @param int $len <p>
* The number of bytes that will be sent to the remote host from
* <i>buf</i>.
* </p>
* @param int $flags <p>
* The value of <i>flags</i> can be any combination of
* the following flags, joined with the binary OR (|)
* operator.
* <table>
* Possible values for <i>flags</i>
* <tr valign="top">
* <td><b>MSG_OOB</b></td>
* <td>
* Send OOB (out-of-band) data.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_EOR</b></td>
* <td>
* Indicate a record mark. The sent data completes the record.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_EOF</b></td>
* <td>
* Close the sender side of the socket and include an appropriate
* notification of this at the end of the sent data. The sent data
* completes the transaction.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_DONTROUTE</b></td>
* <td>
* Bypass routing, use direct interface.
* </td>
* </tr>
* </table>
* </p>
* @return int <b>socket_send</b> returns the number of bytes sent, or <b>FALSE</b> on error.
*/
function socket_send($socket, string $buf, int $len, int $flags): int {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Receives data from a socket whether or not it is connection-oriented
* @link http://php.net/manual/en/function.socket-recvfrom.php
* @param resource $socket <p>
* The <i>socket</i> must be a socket resource previously
* created by socket_create().
* </p>
* @param string $buf <p>
* The data received will be fetched to the variable specified with
* <i>buf</i>.
* </p>
* @param int $len <p>
* Up to <i>len</i> bytes will be fetched from remote host.
* </p>
* @param int $flags <p>
* The value of <i>flags</i> can be any combination of
* the following flags, joined with the binary OR (|)
* operator.
* </p>
* <table>
* Possible values for <i>flags</i>
* <tr valign="top">
* <td>Flag</td>
* <td>Description</td>
* </tr>
* <tr valign="top">
* <td><b>MSG_OOB</b></td>
* <td>
* Process out-of-band data.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_PEEK</b></td>
* <td>
* Receive data from the beginning of the receive queue without
* removing it from the queue.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_WAITALL</b></td>
* <td>
* Block until at least <i>len</i> are received.
* However, if a signal is caught or the remote host disconnects, the
* function may return less data.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_DONTWAIT</b></td>
* <td>
* With this flag set, the function returns even if it would normally
* have blocked.
* </td>
* </tr>
* </table>
* @param string $name <p>
* If the socket is of the type <b>AF_UNIX</b> type,
* <i>name</i> is the path to the file. Else, for
* unconnected sockets, <i>name</i> is the IP address of,
* the remote host, or <b>NULL</b> if the socket is connection-oriented.
* </p>
* @param int $port [optional] <p>
* This argument only applies to <b>AF_INET</b> and
* <b>AF_INET6</b> sockets, and specifies the remote port
* from which the data is received. If the socket is connection-oriented,
* <i>port</i> will be <b>NULL</b>.
* </p>
* @return int <b>socket_recvfrom</b> returns the number of bytes received,
* or <b>FALSE</b> if there was an error. The actual error code can be retrieved by
* calling <b>socket_last_error</b>. This error code may be
* passed to <b>socket_strerror</b> to get a textual explanation
* of the error.
*/
function socket_recvfrom($socket, string &$buf, int $len, int $flags, string &$name, int &$port = null): int {}
/**
* (PHP 4 >= 4.1.0, PHP 5, PHP 7)<br/>
* Sends a message to a socket, whether it is connected or not
* @link http://php.net/manual/en/function.socket-sendto.php
* @param resource $socket <p>
* A valid socket resource created using <b>socket_create</b>.
* </p>
* @param string $buf <p>
* The sent data will be taken from buffer <i>buf</i>.
* </p>
* @param int $len <p>
* <i>len</i> bytes from <i>buf</i> will be
* sent.
* </p>
* @param int $flags <p>
* The value of <i>flags</i> can be any combination of
* the following flags, joined with the binary OR (|)
* operator.
* <table>
* Possible values for <i>flags</i>
* <tr valign="top">
* <td><b>MSG_OOB</b></td>
* <td>
* Send OOB (out-of-band) data.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_EOR</b></td>
* <td>
* Indicate a record mark. The sent data completes the record.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_EOF</b></td>
* <td>
* Close the sender side of the socket and include an appropriate
* notification of this at the end of the sent data. The sent data
* completes the transaction.
* </td>
* </tr>
* <tr valign="top">
* <td><b>MSG_DONTROUTE</b></td>
* <td>
* Bypass routing, use direct interface.
* </td>
* </tr>
* </table>
* </p>
* @param string $addr <p>
* IP address of the remote host.
* </p>
* @param int $port [optional] <p>
* <i>port</i> is the remote port number at which the data
* will be sent.
* </p>
* @return int <b>socket_sendto</b> returns the number of bytes sent to the
* remote host, or <b>FALSE</b> if an error occurred.
*/
function socket_sendto($socket, string $buf, int $len, int $flags, string $addr, int $port = 0): int {}
/**
* (PHP 4 >= 4.3.0, PHP 5, PHP 7)<br/>
* Gets socket options for the socket
* @link http://php.net/manual/en/function.socket-get-option.php
* @param resource $socket <p>
* A valid socket resource created with <b>socket_create</b>
* or <b>socket_accept</b>.
* </p>
* @param int $level <p>
* The <i>level</i> parameter specifies the protocol
* level at which the option resides. For example, to retrieve options at
* the socket level, a <i>level</i> parameter of
* <b>SOL_SOCKET</b> would be used. Other levels, such as
* <b>TCP</b>, can be used by
* specifying the protocol number of that level. Protocol numbers can be
* found by using the <b>getprotobyname</b> function.
* </p>
* @param int $optname <table>
* Available Socket Options
* <tr valign="top">
* <td>Option</td>
* <td>Description</td>
* <td>Type</td>
* </tr>
* <tr valign="top">
* <td><b>SO_DEBUG</b></td>
* <td>
* Reports whether debugging information is being recorded.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_BROADCAST</b></td>
* <td>
* Reports whether transmission of broadcast messages is supported.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_REUSEADDR</b></td>
* <td>
* Reports whether local addresses can be reused.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_KEEPALIVE</b></td>
* <td>
* Reports whether connections are kept active with periodic transmission
* of messages. If the connected socket fails to respond to these messages,
* the connection is broken and processes writing to that socket are notified
* with a SIGPIPE signal.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_LINGER</b></td>
* <td>
* <p>
* Reports whether the <i>socket</i> lingers on
* <b>socket_close</b> if data is present. By default,
* when the socket is closed, it attempts to send all unsent data.
* In the case of a connection-oriented socket,
* <b>socket_close</b> will wait for its peer to
* acknowledge the data.
* </p>
* <p>
* If l_onoff is non-zero and
* l_linger is zero, all the
* unsent data will be discarded and RST (reset) is sent to the
* peer in the case of a connection-oriented socket.
* </p>
* <p>
* On the other hand, if l_onoff is
* non-zero and l_linger is non-zero,
* <b>socket_close</b> will block until all the data
* is sent or the time specified in l_linger
* elapses. If the socket is non-blocking,
* <b>socket_close</b> will fail and return an error.
* </p>
* </td>
* <td>
* array. The array will contain two keys:
* l_onoff and
* l_linger.
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_OOBINLINE</b></td>
* <td>
* Reports whether the <i>socket</i> leaves out-of-band data inline.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_SNDBUF</b></td>
* <td>
* Reports the size of the send buffer.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_RCVBUF</b></td>
* <td>
* Reports the size of the receive buffer.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_ERROR</b></td>
* <td>
* Reports information about error status and clears it.
* </td>
* <td>
* int (cannot be set by <b>socket_set_option</b>)
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_TYPE</b></td>
* <td>
* Reports the <i>socket</i> type (e.g.
* <b>SOCK_STREAM</b>).
* </td>
* <td>
* int (cannot be set by <b>socket_set_option</b>)
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_DONTROUTE</b></td>
* <td>
* Reports whether outgoing messages bypass the standard routing facilities.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_RCVLOWAT</b></td>
* <td>
* Reports the minimum number of bytes to process for <i>socket</i>
* input operations.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_RCVTIMEO</b></td>
* <td>
* Reports the timeout value for input operations.
* </td>
* <td>
* array. The array will contain two keys:
* sec which is the seconds part on the timeout
* value and usec which is the microsecond part
* of the timeout value.
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_SNDTIMEO</b></td>
* <td>
* Reports the timeout value specifying the amount of time that an output
* function blocks because flow control prevents data from being sent.
* </td>
* <td>
* array. The array will contain two keys:
* sec which is the seconds part on the timeout
* value and usec which is the microsecond part
* of the timeout value.
* </td>
* </tr>
* <tr valign="top">
* <td><b>SO_SNDLOWAT</b></td>
* <td>
* Reports the minimum number of bytes to process for <i>socket</i> output operations.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>TCP_NODELAY</b></td>
* <td>
* Reports whether the Nagle TCP algorithm is disabled.
* </td>
* <td>
* int
* </td>
* </tr>
* <tr valign="top">
* <td><b>MCAST_JOIN_GROUP</b></td>
* <td>
* Joins a multicast group. (added in PHP 5.4)
* </td>
* <td>
* array with keys "group", specifying
* a string with an IPv4 or IPv6 multicast address and
* "interface", specifying either an interface
* number (type int) or a string with
* the interface name, like "eth0".
* 0 can be specified to indicate the interface