com php-src: Separate check for process creation and ability to accept connections: sapi/cli/tests/php_cli_server.inc

From: Date: Wed, 19 Jun 2019 09:09:26 +0000
Subject: com php-src: Separate check for process creation and ability to accept connections: sapi/cli/tests/php_cli_server.inc
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-106878@lists.php.net to get a copy of this message
Commit: d6480fa231831feece7403a640b6037c11eec317 Author: Joe Watkins <krakjoe@php.net> Wed, 19 Jun 2019 11:09:26 +0200 Parents: 571c6bc3f3a6e5e2422dd253e04e9dd8dc740f09 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d6480fa231831feece7403a640b6037c11eec317 Log: Separate check for process creation and ability to accept connections Changed paths: M sapi/cli/tests/php_cli_server.inc Diff: diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc index ff4eef0..1a02e7e 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);

« previous php.cvs (#106878) next »