diff options
author | Joe Watkins <krakjoe@php.net> | 2019-06-19 11:09:26 +0200 |
---|---|---|
committer | Joe Watkins <krakjoe@php.net> | 2019-06-19 11:09:26 +0200 |
commit | d6480fa231831feece7403a640b6037c11eec317 (patch) | |
tree | 20b7d8a2a0676a05141ac7543405215c242142d2 /sapi/cli/tests | |
parent | 571c6bc3f3a6e5e2422dd253e04e9dd8dc740f09 (diff) | |
download | php-git-d6480fa231831feece7403a640b6037c11eec317.tar.gz |
Separate check for process creation and ability to accept connections
Diffstat (limited to 'sapi/cli/tests')
-rw-r--r-- | sapi/cli/tests/php_cli_server.inc | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc index ff4eef0e12..1a02e7e0ff 100644 --- a/sapi/cli/tests/php_cli_server.inc +++ b/sapi/cli/tests/php_cli_server.inc @@ -40,35 +40,34 @@ function php_cli_server_start($code = 'echo "Hello world";', $router = 'index.ph $handle = proc_open($cmd, $descriptorspec, $pipes, $doc_root); } - // note: even when server prints 'Listening on localhost:8964...Press Ctrl-C to quit.' - // it might not be listening yet...need to wait until fsockopen() call returns - $error = "Unable to connect to server\n"; + // note: here we check the process is running for ($i=0; $i < 60; $i++) { usleep(50000); // 50ms per try $status = proc_get_status($handle); - $fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT); + // Failure, the server is no longer running if (!($status && $status['running'])) { $error = "Server is not running\n"; break; } - // Success, Connected to servers - if ($fp) { - $error = ''; - break; - } } - if ($fp) { - fclose($fp); - } - - if ($error) { +php_cli_server_start_error: + if (isset($error)) { echo $error; proc_terminate($handle); exit(1); } + // note: here we check the server is listening, even when the server prints + // listening on %s:%d + // it may not be ready to accept connections + if (!fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT)) { + $error = + "Server is not accepting connections\n"; + goto php_cli_server_start_error; + } + register_shutdown_function( function($handle) use($router) { proc_terminate($handle); |