xref: /PHP-5.3/ext/curl/tests/bug48203_multi.phpt (revision 0f26db69)
1--TEST--
2Variation of bug #48203 with curl_multi_exec (Crash when file pointers passed to curl are closed before calling curl_multi_exec)
3--SKIPIF--
4<?php
5if (!extension_loaded("curl")) {
6	exit("skip curl extension not loaded");
7}
8if (false === getenv('PHP_CURL_HTTP_REMOTE_SERVER'))  {
9	exit("skip PHP_CURL_HTTP_REMOTE_SERVER env variable is not defined");
10}
11?>
12--FILE--
13<?php
14
15function checkForClosedFilePointer($curl_option, $description) {
16	$fp = fopen(dirname(__FILE__) . '/bug48203.tmp', 'w');
17
18	$ch1 = curl_init();
19	$ch2 = curl_init();
20
21	$options = array(
22		CURLOPT_RETURNTRANSFER => 1,
23		$curl_option => $fp,
24		CURLOPT_URL => getenv("PHP_CURL_HTTP_REMOTE_SERVER")
25	);
26
27	// we also need to set CURLOPT_VERBOSE to test CURLOPT_STDERR properly
28	if (CURLOPT_STDERR == $curl_option) {
29		$options[CURLOPT_VERBOSE] = 1;
30	}
31
32	if (CURLOPT_INFILE == $curl_option) {
33	    $options[CURLOPT_UPLOAD] = 1;
34	}
35
36	curl_setopt_array($ch1, $options);
37	curl_setopt_array($ch2, $options);
38
39	fclose($fp); // <-- premature close of $fp caused a crash!
40
41	$mh = curl_multi_init();
42
43	curl_multi_add_handle($mh, $ch1);
44	curl_multi_add_handle($mh, $ch2);
45
46	$active = 0;
47	do {
48		curl_multi_exec($mh, $active);
49	} while ($active > 0);
50
51	curl_multi_remove_handle($mh, $ch1);
52	curl_multi_remove_handle($mh, $ch2);
53	curl_multi_close($mh);
54
55	echo "Ok for $description\n";
56}
57
58$options_to_check = array(
59	"CURLOPT_STDERR", "CURLOPT_WRITEHEADER", "CURLOPT_FILE", "CURLOPT_INFILE"
60);
61
62foreach($options_to_check as $option) {
63	checkForClosedFilePointer(constant($option), $option);
64}
65
66?>
67--CLEAN--
68<?php @unlink(dirname(__FILE__) . '/bug48203.tmp'); ?>
69--EXPECTF--
70Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36
71
72Warning: curl_multi_exec(): CURLOPT_STDERR resource has gone away, resetting to stderr in %sbug48203_multi.php on line 36
73%A
74Ok for CURLOPT_STDERR
75%A
76Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36
77
78Warning: curl_multi_exec(): CURLOPT_WRITEHEADER resource has gone away, resetting to default in %sbug48203_multi.php on line 36
79Ok for CURLOPT_WRITEHEADER
80
81Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
82
83Warning: curl_multi_exec(): CURLOPT_FILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
84%A
85Ok for CURLOPT_FILE
86
87Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
88
89Warning: curl_multi_exec(): CURLOPT_INFILE resource has gone away, resetting to default in %sbug48203_multi.php on line 36
90Ok for CURLOPT_INFILE
91