com php-src: refactor a little more to add some more useful error messages and raise the limits on waiting for slow machines: sapi/cli/tes
ts/php_cli_server.inc
| From: | Joe Watkins | Date: | Wed, 19 Jun 2019 09:41:24 +0000 |
| Subject: | com php-src: refactor a little more to add some more useful error messages and raise the limits on waiting for slow machines: sapi/cli/tes ts/php_cli_server.inc |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106879@lists.php.net to get a copy of this message | ||
Commit: eda5d8afcf601cb521ba3c9536c7d1a4ae5fb089
Author: Joe Watkins <krakjoe@php.net> Wed, 19 Jun 2019 11:41:24 +0200
Parents: d6480fa231831feece7403a640b6037c11eec317
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=eda5d8afcf601cb521ba3c9536c7d1a4ae5fb089
Log:
refactor a little more to add some more useful error messages and raise the limits on waiting for
slow machines
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 1a02e7e..1f7091b 100644
--- a/sapi/cli/tests/php_cli_server.inc
+++ b/sapi/cli/tests/php_cli_server.inc
@@ -6,6 +6,7 @@ define ("PHP_CLI_SERVER_ADDRESS",
PHP_CLI_SERVER_HOSTNAME.":".PHP_CLI_SERVER_POR
function php_cli_server_start($code = 'echo "Hello world";', $router =
'index.php', $cmd_args = null) {
$php_executable = getenv('TEST_PHP_EXECUTABLE');
$doc_root = __DIR__;
+ $error = null;
if ($code) {
file_put_contents($doc_root . '/' . ($router ?: 'index.php'), '<?php
' . $code . ' ?>');
@@ -41,33 +42,63 @@ function php_cli_server_start($code = 'echo "Hello world";',
$router = 'index.ph
}
// note: here we check the process is running
- for ($i=0; $i < 60; $i++) {
- usleep(50000); // 50ms per try
+ for ($i=0; $i < 120; $i++) {
$status = proc_get_status($handle);
- // Failure, the server is no longer running
- if (!($status && $status['running'])) {
- $error = "Server is not running\n";
+ if (!$status || !$status['running']) {
+ if ($status &&
+ ($status['running'] == false && $status['exitcode'] !=
0)) {
+ $error =
+ "Server could not be started\n";
+ break;
+ }
+
+ usleep(50000); // 50ms per try
+ continue;
+ }
+
+ if ($status['signaled']) {
+ $error =
+ "Server was terminated with {$status['termsig']}\n";
break;
}
+
+ if ($status['stopped']) {
+ $error =
+ "Server was stopped with {$status['stopsig']}\n";
+ break;
+ }
+
+ // 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
+ $start = time();
+
+ for ($try = 0; $try < 120; $try++) {
+ $error = @fsockopen(
+ PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT) ?
+ null :
+ sprintf(
+ "Server is not accepting connections after %d seconds\n",
+ time() - $start);
+
+ if (!$error) {
+ break 2;
+ }
+
+ usleep(50000);
+ }
+
+ break;
}
php_cli_server_start_error:
- if (isset($error)) {
+ if ($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);