From: Nikita Popov Date: Wed, 8 Apr 2020 15:10:20 +0000 (+0200) Subject: Add php_cli_server_connect() helper X-Git-Tag: php-7.4.7RC1~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=132749122426ee21171b2b3caccfaf86e24b4adf;p=php Add php_cli_server_connect() helper To encapsulate the repeated fsockopen() code. This gives us a chance to control the timeout in one place: Raise it to one second. --- diff --git a/sapi/cli/tests/bug43177.phpt b/sapi/cli/tests/bug43177.phpt index 87dc8927ff..2ab08228b9 100644 --- a/sapi/cli/tests/bug43177.phpt +++ b/sapi/cli/tests/bug43177.phpt @@ -35,15 +35,10 @@ php_cli_server_start(<<<'SCRIPT' SCRIPT ); -list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); -$port = intval($port)?:80; +$host = PHP_CLI_SERVER_HOSTNAME; foreach(array("parse", "fatal", "fatal2", "compile") as $url) { - $fp = fsockopen($host, $port, $errno, $errstr, 0.5); - if (!$fp) { - die("connect failed"); - } - + $fp = php_cli_server_connect(); if(fwrite($fp, <<
diff --git a/sapi/cli/tests/php_cli_server_004.phpt b/sapi/cli/tests/php_cli_server_004.phpt index 9c93de3f92..d9c3b171f2 100644 --- a/sapi/cli/tests/php_cli_server_004.phpt +++ b/sapi/cli/tests/php_cli_server_004.phpt @@ -11,13 +11,8 @@ include "skipif.inc"; include "php_cli_server.inc"; php_cli_server_start('foreach($_SERVER as $k=>$v) { if (!strncmp($k, "HTTP", 4)) var_dump( $k . ":" . $v); }'); -list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); -$port = intval($port)?:80; - -$fp = fsockopen($host, $port, $errno, $errstr, 0.5); -if (!$fp) { - die("connect failed"); -} +$host = PHP_CLI_SERVER_HOSTNAME; +$fp = php_cli_server_connect(); if(fwrite($fp, <<
'); -list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); -$port = intval($port)?:80; - -$fp = fsockopen($host, $port, $errno, $errstr, 0.5); -if (!$fp) { - die("connect failed"); -} +$host = PHP_CLI_SERVER_HOSTNAME; +$fp = php_cli_server_connect(); if(fwrite($fp, <<
(.*?)<\/style>/s", "", $output), "\ fclose($fp); $output = ''; -$fp = fsockopen($host, $port, $errno, $errstr, 0.5); -if (!$fp) { - die("connect failed"); -} +$fp = php_cli_server_connect(); if(fwrite($fp, <<
"); -list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); -$port = intval($port)?:80; $output = ''; - -$fp = fsockopen($host, $port, $errno, $errstr, 0.5); -if (!$fp) { - die("connect failed"); -} +$host = PHP_CLI_SERVER_HOSTNAME; +$fp = php_cli_server_connect(); if(fwrite($fp, <<