]> granicus.if.org Git - php/commitdiff
improve the test, let it say about errors
authorXinchen Hui <laruence@php.net>
Thu, 17 Nov 2011 02:22:06 +0000 (02:22 +0000)
committerXinchen Hui <laruence@php.net>
Thu, 17 Nov 2011 02:22:06 +0000 (02:22 +0000)
sapi/cli/tests/php_cli_server.inc

index ab754eb4082a2cad2ee366964df5e9010e09c68c..4a8170955b867e24658a3871cb066830b8184199 100644 (file)
@@ -12,7 +12,7 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE)
        $descriptorspec = array(
                0 => STDIN,
                1 => STDOUT,
-               2 => STDERR,
+               2 => array("pipe", "w"),
        );
 
        if (substr(PHP_OS, 0, 3) == 'WIN') {
@@ -21,25 +21,35 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE)
                        $cmd .= " {$router}";
                }
 
-               $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true,  "suppress_errors" => true));
+               $handle = proc_open(addslashes($cmd), $descriptorspec, $pipes, $doc_root, NULL, array("bypass_shell" => true));
        } else {
                $cmd = "exec {$php_executable} -t {$doc_root} -S " . PHP_CLI_SERVER_ADDRESS;
                if (!$no_router) {
                        $cmd .= " {$router}";
                }
-               $cmd .= " 2>/dev/null";
 
                $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root);
        }
 
+       //@FIXME is there a better way to make sure the process is ready?
+       usleep(50000);
+
+       stream_set_blocking($pipes[2], 0);
+       if ($err = stream_get_contents($pipes[2])) {
+               fclose($pipes[2]);
+               proc_terminate($handle);
+               @unlink(__DIR__ . "/{$router}");
+               die("Cli sever could not be started: " . $err);
+       }
+
        register_shutdown_function(
-               function($handle) use($router) {
+               function($handle, $router, $pipes) {
+                       stream_get_contents($pipes[2]);
+                       fclose($pipes[2]);
                        proc_terminate($handle);
                        @unlink(__DIR__ . "/{$router}");
                },
-                       $handle
+                       $handle, $router, $pipes
                );
-       usleep(50000);
 }
 ?>
-