xref: /PHP-5.5/ext/standard/tests/file/bug52820.phpt (revision daf9357d)
1--TEST--
2Bug #52820 (writes to fopencookie FILE* not committed when seeking the stream)
3--SKIPIF--
4<?php
5if (!function_exists('leak_variable'))
6   die("skip only for debug builds");
7/* unfortunately no standard function does a cast to FILE*, so we need
8 * curl to test this */
9if (!extension_loaded("curl")) exit("skip curl extension not loaded");
10$handle=curl_init('http://127.0.0.1:37349/');
11curl_setopt($handle, CURLOPT_VERBOSE, true);
12curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
13if (!curl_setopt($handle, CURLOPT_STDERR, fopen("php://memory", "w+")))
14    die("skip fopencookie not supported on this platform");
15--FILE--
16<?php
17function do_stuff($url) {
18    $handle=curl_init('http://127.0.0.1:37349/');
19    curl_setopt($handle, CURLOPT_VERBOSE, true);
20    curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
21    curl_setopt($handle, CURLOPT_STDERR, $o = fopen($url, "w+"));
22    curl_exec($handle);
23    echo "About to rewind!\n";
24    rewind($o);
25    echo stream_get_contents($o);
26    return $o;
27}
28
29echo "temp stream (close after):\n";
30fclose(do_stuff("php://temp"));
31
32echo "\nmemory stream (close after):\n";
33fclose(do_stuff("php://memory"));
34
35echo "\ntemp stream (leak):\n";
36leak_variable(do_stuff("php://temp"), true);
37
38echo "\nmemory stream (leak):\n";
39leak_variable(do_stuff("php://memory"), true);
40
41echo "\nDone.\n";
42--EXPECTF--
43temp stream (close after):
44About to rewind!
45* %ATrying 127.0.0.1...%AConnection refused%A
46* Closing connection%A%d
47
48memory stream (close after):
49About to rewind!
50* %ATrying 127.0.0.1...%AConnection refused%A
51* Closing connection%A%d
52
53temp stream (leak):
54About to rewind!
55* %ATrying 127.0.0.1...%AConnection refused%A
56* Closing connection%A%d
57
58memory stream (leak):
59About to rewind!
60* %ATrying 127.0.0.1...%AConnection refused%A
61* Closing connection%A%d
62
63Done.
64