mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
refactor a little more to add some more useful error messages and raise the limits on waiting for slow machines
This commit is contained in:
parent
d6480fa231
commit
eda5d8afcf
1 changed files with 46 additions and 15 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue