22define ("PHP_CLI_SERVER_ADDRESS " , "localhost:8964 " );
33
44function php_cli_server_start ($ code = 'echo "Hello world"; ' , $ no_router = FALSE ) {
5- $ php_executable = getenv ('TEST_PHP_EXECUTABLE ' );
5+ $ php_executable = getenv ('TEST_PHP_EXECUTABLE ' );
66 $ doc_root = __DIR__ ;
77 $ router = "index.php " ;
88 file_put_contents ($ doc_root . '/ ' . $ router , '<?php ' . $ code . ' ?> ' );
@@ -13,21 +13,31 @@ function php_cli_server_start($code = 'echo "Hello world";', $no_router = FALSE)
1313 2 => STDERR ,
1414 );
1515
16- $ cmd = "exec {$ php_executable } -t {$ doc_root } -S " . PHP_CLI_SERVER_ADDRESS ;
16+ if (substr (PHP_OS , 0 , 3 ) == 'WIN ' ) {
17+ $ cmd = "{$ php_executable } -t {$ doc_root } -S " . PHP_CLI_SERVER_ADDRESS ;
18+ if (!$ no_router ) {
19+ $ cmd .= " {$ router }" ;
20+ }
1721
18- if (!$ no_router ) {
19- $ cmd .= " {$ router }" ;
20- }
22+ $ handle = proc_open (addslashes ($ cmd ), $ descriptorspec , $ pipes , $ doc_root , NULL , array ("bypass_shell " => true , "suppress_errors " => true ));
23+ } else {
24+ $ cmd = "exec {$ php_executable } -t {$ doc_root } -S " . PHP_CLI_SERVER_ADDRESS ;
25+ if (!$ no_router ) {
26+ $ cmd .= " {$ router }" ;
27+ }
28+ $ cmd .= " 2>/dev/null " ;
2129
22- $ handle = proc_open ($ cmd , $ descriptorspec , $ pipes , $ doc_root );
30+ $ handle = proc_open ($ cmd , $ descriptorspec , $ pipes , $ doc_root );
31+ }
2332
24- register_shutdown_function (
25- function ($ handle ) use ($ router ) {
26- proc_terminate ($ handle );
27- @unlink (__DIR__ . "/ {$ router }" );
28- },
29- $ handle
30- );
33+ register_shutdown_function (
34+ function ($ handle ) use ($ router ) {
35+ proc_terminate ($ handle );
36+ @unlink (__DIR__ . "/ {$ router }" );
37+ },
38+ $ handle
39+ );
3140 usleep (50000 );
3241}
3342?>
43+
0 commit comments