1--TEST--
2Bug #70198 Checking liveness does not work as expected
3--SKIPIF--
4<?php
5if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
6?>
7--CONFLICTS--
8server
9--FILE--
10<?php
11
12/* What is checked here is
13    - start a server and listen
14    - as soon as client connects, close connection and exit
15    - on the client side - sleep(1) and check feof()
16*/
17
18$srv_addr = "tcp://127.0.0.1:8964";
19$srv_fl = __DIR__ . "/bug70198_svr_" . md5(uniqid()) . ".php";
20$srv_fl_escaped = escapeshellarg($srv_fl);
21$srv_fl_cont = <<<SRV
22<?php
23\$socket = stream_socket_server('$srv_addr', \$errno, \$errstr);
24
25if (!\$socket) {
26    echo "\$errstr (\$errno)\\n";
27} else {
28    if (\$conn = stream_socket_accept(\$socket, 3)) {
29        sleep(1);
30        /* just close the connection immediately after accepting,
31            the client side will need wait a bit longer to realize it.*/
32        fclose(\$conn);
33    }
34    fclose(\$socket);
35}
36SRV;
37file_put_contents($srv_fl, $srv_fl_cont);
38$dummy0 = $dummy1 = array();
39$srv_proc = proc_open(getenv('TEST_PHP_EXECUTABLE_ESCAPED') . " -n $srv_fl_escaped", $dummy0, $dummy1);
40
41$i = 0;
42/* wait a bit for the server startup */
43sleep(1);
44$fp = stream_socket_client($srv_addr, $errno, $errstr, 2);
45if (!$fp) {
46    echo "$errstr ($errno)\n";
47} else {
48    stream_set_blocking($fp, 0);
49    sleep(2);
50    while (!feof($fp)) {
51        ++$i;
52    }
53    fclose($fp);
54    var_dump($i);
55}
56
57proc_close($srv_proc);
58unlink($srv_fl);
59?>
60--EXPECT--
61int(0)
62