Skip to content

Commit c5d4c45

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents 3a2fa48 + e691a98 commit c5d4c45

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ PHP NEWS
1414
. Fixed bug #78525 (Memory leak in pdo when reusing native prepared
1515
statements). (Nikita)
1616

17+
- Standard:
18+
. Fixed bug #76342 (file_get_contents waits twice specified timeout).
19+
(Thomas Calvet)
20+
1721
12 Sep 2019, PHP 7.3.10RC1
1822

1923
- Core:

ext/standard/http_fopen_wrapper.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,11 @@ static php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper,
726726
}
727727
ZVAL_STRINGL(&http_response, tmp_line, tmp_line_len);
728728
zend_hash_next_index_insert(Z_ARRVAL_P(response_header), &http_response);
729+
} else {
730+
php_stream_close(stream);
731+
stream = NULL;
732+
php_stream_wrapper_log_error(wrapper, options, "HTTP request failed!");
733+
goto out;
729734
}
730735
} else {
731736
php_stream_wrapper_log_error(wrapper, options, "HTTP request failed, unexpected end of socket!");

ext/standard/tests/http/bug76342.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #76342 (file_get_contents waits twice specified timeout)
3+
--INI--
4+
allow_url_fopen=1
5+
--SKIPIF--
6+
<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
7+
--FILE--
8+
<?php
9+
require 'server.inc';
10+
11+
$options = [
12+
'http' => [
13+
'timeout' => '0.1',
14+
],
15+
];
16+
17+
$ctx = stream_context_create($options);
18+
19+
$pid = http_server_sleep('tcp://127.0.0.1:12342');
20+
21+
$start = microtime(true);
22+
file_get_contents('http://127.0.0.1:12342/', false, $ctx);
23+
if (microtime(true) - $start >= 0.2) {
24+
echo 'FAIL';
25+
}
26+
27+
http_server_kill($pid);
28+
29+
?>
30+
DONE
31+
--EXPECTF--
32+
Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! in %s on line %d
33+
DONE

ext/standard/tests/http/server.inc

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,7 @@ function http_server_skipif($socket_string) {
77
if (!stream_socket_server($socket_string)) die('skip stream_socket_server() failed');
88
}
99

10-
/* Minimal HTTP server with predefined responses.
11-
*
12-
* $socket_string is the socket to create and listen on (e.g. tcp://127.0.0.1:1234)
13-
* $files is an array of files containing N responses for N expected requests. Server dies after N requests.
14-
* $output is a stream on which everything sent by clients is written to
15-
*/
16-
function http_server($socket_string, array $files, &$output = null) {
17-
10+
function http_server_init($socket_string, &$output = null) {
1811
pcntl_alarm(60);
1912

2013
$server = stream_socket_server($socket_string, $errno, $errstr);
@@ -36,6 +29,21 @@ function http_server($socket_string, array $files, &$output = null) {
3629
return $pid;
3730
}
3831

32+
return $server;
33+
}
34+
35+
/* Minimal HTTP server with predefined responses.
36+
*
37+
* $socket_string is the socket to create and listen on (e.g. tcp://127.0.0.1:1234)
38+
* $files is an array of files containing N responses for N expected requests. Server dies after N requests.
39+
* $output is a stream on which everything sent by clients is written to
40+
*/
41+
function http_server($socket_string, array $files, &$output = null) {
42+
43+
if (!is_resource($server = http_server_init($socket_string, $output))) {
44+
return $server;
45+
}
46+
3947
foreach($files as $file) {
4048

4149
$sock = stream_socket_accept($server);
@@ -84,6 +92,24 @@ function http_server($socket_string, array $files, &$output = null) {
8492
exit(0);
8593
}
8694

95+
function http_server_sleep($socket_string, $micro_seconds = 500000)
96+
{
97+
if (!is_resource($server = http_server_init($socket_string, $output))) {
98+
return $server;
99+
}
100+
101+
$sock = stream_socket_accept($server);
102+
if (!$sock) {
103+
exit(1);
104+
}
105+
106+
usleep($micro_seconds);
107+
108+
fclose($sock);
109+
110+
exit(0);
111+
}
112+
87113
function http_server_kill($pid) {
88114
posix_kill($pid, SIGTERM);
89115
pcntl_waitpid($pid, $status);

0 commit comments

Comments
 (0)