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_cont = <<<SRV
21<?php
22\$socket = stream_socket_server('$srv_addr', \$errno, \$errstr);
23
24if (!\$socket) {
25	echo "\$errstr (\$errno)\\n";
26} else {
27	if (\$conn = stream_socket_accept(\$socket, 3)) {
28		sleep(1);
29		/* just close the connection immediately after accepting,
30			the client side will need wait a bit longer to realize it.*/
31		fclose(\$conn);
32	}
33	fclose(\$socket);
34}
35SRV;
36file_put_contents($srv_fl, $srv_fl_cont);
37$dummy0 = $dummy1 = array();
38$srv_proc = proc_open(PHP_BINARY . " -n $srv_fl", $dummy0, $dummy1);
39
40$i = 0;
41/* wait a bit for the server startup */
42sleep(1);
43$fp = stream_socket_client($srv_addr, $errno, $errstr, 2);
44if (!$fp) {
45	echo "$errstr ($errno)\n";
46} else {
47	stream_set_blocking($fp, 0);
48	sleep(2);
49	while (!feof($fp)) {
50		++$i;
51	}
52	fclose($fp);
53	var_dump($i);
54}
55
56proc_close($srv_proc);
57unlink($srv_fl);
58?>
59==DONE==
60--EXPECT--
61int(0)
62==DONE==
63