xref: /PHP-7.2/ext/standard/tests/http/bug60570.phpt (revision f1d7e3ca)
1--TEST--
2Bug #60570 (Stream context leaks when http request fails)
3--SKIPIF--
4<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
5--INI--
6allow_url_fopen=1
7allow_url_include=1
8--FILE--
9<?php
10require 'server.inc';
11
12function do_test() {
13
14	$responses = array(
15		"data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n",
16		"data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n",
17		"data://text/plain,HTTP/1.0 404 Not Found\r\n\r\n"
18	);
19
20	$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
21
22	$a = $b = count(get_resources());
23
24	$i = 3;
25	while ($i--) {
26		$context = stream_context_create(array('http'=>array('timeout'=>1)));
27		file_get_contents('http://127.0.0.1:12342/', 0, $context);
28		unset($context);
29
30		$b = $a;
31		$a = count(get_resources());
32	}
33
34	http_server_kill($pid);
35
36	echo "leak? penultimate iteration: $b, last one: $a\n";
37	var_dump($a == $b);
38}
39
40do_test();
41--EXPECTF--
42Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
43 in %s on line %d
44
45Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
46 in %s on line %d
47
48Warning: file_get_contents(http://127.0.0.1:12342/): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
49 in %s on line %d
50leak? penultimate iteration: %d, last one: %d
51bool(true)
52