Skip to content

Commit 1327491

Browse files
committed
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.
1 parent 5317ea6 commit 1327491

33 files changed

+83
-251
lines changed

sapi/cli/tests/bug43177.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ php_cli_server_start(<<<'SCRIPT'
3535
SCRIPT
3636
);
3737

38-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
39-
$port = intval($port)?:80;
38+
$host = PHP_CLI_SERVER_HOSTNAME;
4039

4140
foreach(array("parse", "fatal", "fatal2", "compile") as $url) {
42-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
43-
if (!$fp) {
44-
die("connect failed");
45-
}
46-
41+
$fp = php_cli_server_connect();
4742
if(fwrite($fp, <<<HEADER
4843
GET /$url HTTP/1.1
4944
Host: {$host}

sapi/cli/tests/bug61679.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ echo "This should never echo";
1212
PHP
1313
);
1414

15-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
16-
$port = intval($port)?:80;
17-
18-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
19-
if (!$fp) {
20-
die("connect failed");
21-
}
15+
$host = PHP_CLI_SERVER_HOSTNAME;
16+
$fp = php_cli_server_connect();
2217

2318
// Send a request with a fictitious request method,
2419
// I like smurfs, the smurf everything.

sapi/cli/tests/bug61977.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ $mimetypes = ['html', 'htm', 'svg', 'css', 'js', 'png', 'webm', 'ogv', 'ogg'];
1717

1818
function test_mimetypes($mimetypes) {
1919
foreach ($mimetypes as $mimetype) {
20-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
21-
$port = intval($port) ? : 80;
22-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
20+
$host = PHP_CLI_SERVER_HOSTNAME;
21+
$fp = php_cli_server_connect();
2322
if (!$fp) die('Connect failed');
2423
file_put_contents(__DIR__ . "/foo.{$mimetype}", '');
2524
$header = <<<HEADER

sapi/cli/tests/bug65066_100.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ include "skipif.inc";
1111
include "php_cli_server.inc";
1212
php_cli_server_start('http_response_code(100);');
1313

14-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
15-
$port = intval($port)?:80;
16-
17-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
18-
if (!$fp) {
19-
die("connect failed");
20-
}
14+
$host = PHP_CLI_SERVER_HOSTNAME;
15+
$fp = php_cli_server_connect();
2116

2217
if(fwrite($fp, <<<HEADER
2318
GET / HTTP/1.1

sapi/cli/tests/bug65066_422.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ include "skipif.inc";
1111
include "php_cli_server.inc";
1212
php_cli_server_start('http_response_code(422);');
1313

14-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
15-
$port = intval($port)?:80;
16-
17-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
18-
if (!$fp) {
19-
die("connect failed");
20-
}
14+
$host = PHP_CLI_SERVER_HOSTNAME;
15+
$fp = php_cli_server_connect();
2116

2217
if(fwrite($fp, <<<HEADER
2318
GET / HTTP/1.1

sapi/cli/tests/bug65066_511.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ include "skipif.inc";
1111
include "php_cli_server.inc";
1212
php_cli_server_start('http_response_code(511);');
1313

14-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
15-
$port = intval($port)?:80;
16-
17-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
18-
if (!$fp) {
19-
die("connect failed");
20-
}
14+
$host = PHP_CLI_SERVER_HOSTNAME;
15+
$fp = php_cli_server_connect();
2116

2217
if(fwrite($fp, <<<HEADER
2318
GET / HTTP/1.1

sapi/cli/tests/bug65633.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ var_dump($_COOKIE, $_SERVER['HTTP_FOO']);
1212
PHP
1313
);
1414

15-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
16-
$port = intval($port)?:80;
17-
18-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
19-
if (!$fp) {
20-
die("connect failed");
21-
}
15+
$host = PHP_CLI_SERVER_HOSTNAME;
16+
$fp = php_cli_server_connect();
2217

2318
if(fwrite($fp, <<<HEADER
2419
GET / HTTP/1.1

sapi/cli/tests/bug66606_2.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ include "skipif.inc";
1111
include "php_cli_server.inc";
1212
php_cli_server_start('var_dump($_SERVER["CONTENT_TYPE"], $_SERVER["CONTENT_LENGTH"])');
1313

14-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
15-
$port = intval($port)?:80;
16-
17-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
18-
if (!$fp) {
19-
die("connect failed");
20-
}
14+
$host = PHP_CLI_SERVER_HOSTNAME;
15+
$fp = php_cli_server_connect();
2116

2217
if (fwrite($fp, <<<HEADER
2318
POST /index.php HTTP/1.1

sapi/cli/tests/bug66830.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,8 @@ header(' ');
1212
PHP
1313
);
1414

15-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
16-
$port = intval($port)?:80;
17-
18-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
19-
if (!$fp) {
20-
die("connect failed");
21-
}
15+
$host = PHP_CLI_SERVER_HOSTNAME;
16+
$fp = php_cli_server_connect();
2217

2318
if(fwrite($fp, <<<HEADER
2419
GET / HTTP/1.1

sapi/cli/tests/bug67429_1.phpt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@ http_response_code(308);
1313
PHP
1414
);
1515

16-
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS);
17-
$port = intval($port)?:80;
18-
19-
$fp = fsockopen($host, $port, $errno, $errstr, 0.5);
20-
if (!$fp) {
21-
die("connect failed");
22-
}
16+
$host = PHP_CLI_SERVER_HOSTNAME;
17+
$fp = php_cli_server_connect();
2318

2419
if(fwrite($fp, <<<HEADER
2520
GET / HTTP/1.1

0 commit comments

Comments
 (0)