add pipelining test
[m6w6/ext-http] / tests / server.inc
1 <?php
2
3 function serve(callable $cb) {
4 foreach (range(8000, 9000) as $port) {
5 if (($server = stream_socket_server("tcp://localhost:$port"))) {
6 fprintf(STDERR, "%s\n", $port);
7 if (($client = stream_socket_accept($server))) {
8 $cb($client);
9 }
10 return;
11 }
12 }
13 }
14
15 function server($file, callable $cb) {
16 $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
17 if (($proc = proc_open(PHP_BINARY . " $file", $spec, $pipes, __DIR__))) {
18 $port = trim(fgets($pipes[2]));
19
20 $cb($port,
21 $stdin = $pipes[0],
22 $stdout = $pipes[1],
23 $stderr = $pipes[2]);
24
25 fpassthru($stderr);
26 fpassthru($stdout);
27 }
28 }