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))) {
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]));