1--TEST--
2socket_get_option MEMINFO;
3--EXTENSIONS--
4sockets
5--SKIPIF--
6<?php
7if (!defined("SO_MEMINFO")) die('skip SO_MEMINFO test');
8?>
9--FILE--
10<?php
11$server = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
12if (!$server) {
13    die('Unable to create AF_INET socket [server]');
14}
15
16if (!socket_bind($server, '127.0.0.1', 0)) {
17    die("Unable to bind to 127.0.0.1");
18}
19
20if (!socket_listen($server, 2)) {
21    die('Unable to listen on socket');
22}
23
24socket_getsockname($server, $unused, $port);
25
26/* Connect to it */
27$client = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
28if (!$client) {
29    die('Unable to create AF_INET socket [client]');
30}
31if (!socket_connect($client, '127.0.0.1', $port)) {
32    die('Unable to connect to server socket');
33}
34
35/* Accept that connection */
36$socket = socket_accept($server);
37if (!$socket) {
38    die('Unable to accept connection');
39}
40
41socket_write($client, "SO_MEMINFO\n");
42
43socket_read($socket, strlen("SO_MEMINFO"), PHP_BINARY_READ);
44$data = socket_get_option($socket, SOL_SOCKET, SO_MEMINFO);
45var_dump($data);
46
47socket_close($client);
48socket_close($socket);
49socket_close($server);
50?>
51--EXPECTF--
52array(9) {
53  ["rmem_alloc"]=>
54  int(%d)
55  ["rcvbuf"]=>
56  int(%d)
57  ["wmem_alloc"]=>
58  int(%d)
59  ["sndbuf"]=>
60  int(%d)
61  ["fwd_alloc"]=>
62  int(%d)
63  ["wmem_queued"]=>
64  int(%d)
65  ["optmem"]=>
66  int(%d)
67  ["backlog"]=>
68  int(%d)
69  ["drops"]=>
70  int(%d)
71}
72