summaryrefslogtreecommitdiff
path: root/sapi/cli/tests
diff options
context:
space:
mode:
authorJoe Watkins <krakjoe@php.net>2019-06-19 11:41:24 +0200
committerJoe Watkins <krakjoe@php.net>2019-06-19 11:41:24 +0200
commiteda5d8afcf601cb521ba3c9536c7d1a4ae5fb089 (patch)
tree22ad8ced0eef36337e4b6ee916aaca8f9a573fa4 /sapi/cli/tests
parentd6480fa231831feece7403a640b6037c11eec317 (diff)
downloadphp-git-eda5d8afcf601cb521ba3c9536c7d1a4ae5fb089.tar.gz
refactor a little more to add some more useful error messages and raise the limits on waiting for slow machines
Diffstat (limited to 'sapi/cli/tests')
-rw-r--r--sapi/cli/tests/php_cli_server.inc61
1 files changed, 46 insertions, 15 deletions
diff --git a/sapi/cli/tests/php_cli_server.inc b/sapi/cli/tests/php_cli_server.inc
index 1a02e7e0ff..1f7091be5c 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);