com php-src: Fix test failed, the fsockopen will be refused immediately if the server is not set up.: sapi/cli/tests/php_cli_server. inc
| From: | Xinchen Hui | Date: | Wed, 09 May 2012 03:21:24 +0000 |
| Subject: | com php-src: Fix test failed, the fsockopen will be refused immediately if the server is not set up.: sapi/cli/tests/php_cli_server. inc | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-69011@lists.php.net to get a copy of this message | ||
Commit: 7b2ab569976f63b22ba1c69e78e782a693d5076a
Author: Xinchen Hui <laruence@php.net> Wed, 9 May 2012 11:21:24 +0800
Parents: f46a064760bd99223d8a8aec9df9807bab262022
Branches: PHP-5.4
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7b2ab569976f63b22ba1c69e78e782a693d5076a
Log:
Fix test failed, the fsockopen will be refused immediately if the server is not set up.
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 d24a679...3479cd0 100644
--- a/sapi/cli/tests/php_cli_server.inc
+++ b/sapi/cli/tests/php_cli_server.inc
@@ -37,16 +37,14 @@ function php_cli_server_start($code = 'echo "Hello world";',
$no_router = FALSE)
// 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
- $fp = fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT);
- if ($fp) {
- // server will report Unexpected EOF error (socket opened, closed without writing
- // anything) but that can be ignored
- fclose($fp);
- } else {
- // test will fail to connect if server doesn't start listening/accepting
- // in the next few microseconds
- }
+ $i = 0;
+ while (($i++ < 5) && !($fp = @fsockopen(PHP_CLI_SERVER_HOSTNAME,
PHP_CLI_SERVER_PORT))) {
+ usleep(10000);
+ }
+ if ($fp) {
+ fclose($fp);
+ }
register_shutdown_function(
function($handle) use($router) {
@@ -56,7 +54,6 @@ function php_cli_server_start($code = 'echo "Hello world";',
$no_router = FALSE)
$handle
);
// don't bother sleeping, server is already up
- //usleep(50000);
// 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.