com php-src: Make Opcache tests using the cli server more reliable: ext/opcache/tests/php_cli_server.inc
| From: | Nikita Popov | Date: | Thu, 29 Dec 2016 19:56:45 +0000 |
| Subject: | com php-src: Make Opcache tests using the cli server more reliable: ext/opcache/tests/php_cli_server.inc | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-96440@lists.php.net to get a copy of this message | ||
Commit: d0fcc741100840a9d27bed8ace1ad6224a4e34a9
Author: Mitch Hagstrand <mhagstrand@gmail.com> Wed, 28 Dec 2016 19:29:36 -0800
Committer: Nikita Popov <nikic@php.net> Thu, 29 Dec 2016 20:56:45 +0100
Parents: 88d1a2c5aab441fd322683f8d21667932aeec636
Branches: PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d0fcc741100840a9d27bed8ace1ad6224a4e34a9
Log:
Make Opcache tests using the cli server more reliable
Same fix already applied to ext/curl/tests/server.inc
and sapi/cli/tests/php_cli_server.inc
1. Increases the amount of time for the PHP built-in server to accept a connection
2. Outputs an error if the PHP built-in server fails
Changed paths:
M ext/opcache/tests/php_cli_server.inc
Diff:
diff --git a/ext/opcache/tests/php_cli_server.inc b/ext/opcache/tests/php_cli_server.inc
index 0878bfa..ca6854f 100644
--- a/ext/opcache/tests/php_cli_server..inc
+++ b/ext/opcache/tests/php_cli_server.inc
@@ -20,28 +20,43 @@ function php_cli_server_start($ini = "") {
$cmd = "exec {$php_executable} -t {$doc_root} $ini -S " . PHP_CLI_SERVER_ADDRESS .
" 2>/dev/null";
$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
- $i = 0;
- while (($i++ < 30) && !($fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME,
PHP_CLI_SERVER_PORT))) {
- usleep(10000);
- }
+ $error = "Unable to connect to servers\n";
+ for ($i=0; $i < 60; $i++) {
+ usleep(25000); // 25ms 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 ($fp) {
+ fclose($fp);
+ }
+
+ if ($error) {
+ echo $error;
+ proc_terminate($handle);
+ exit(1);
+ }
register_shutdown_function(
function($handle) {
proc_terminate($handle);
},
- $handle
- );
- // don't bother sleeping, server is already up
- // server can take a variable amount of time to be up, so just sleeping a guessed amount of time
- // does not work. this is why tests sometimes pass and sometimes fail. to get a reliable pass
- // sleeping doesn't work.
+ $handle
+ );
+
}
?>