xref: /PHP-5.4/ext/standard/tests/file/bug52820.phpt (revision ac40c0b5)
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* About to connect() to 127.0.0.1 port 37349%r.*%r
46*   Trying 127.0.0.1...%A* Connection refused
47* couldn't connect to host%S
48* Closing connection #0
49
50memory stream (close after):
51About to rewind!
52* About to connect() to 127.0.0.1 port 37349%r.*%r
53*   Trying 127.0.0.1...%A* Connection refused
54* couldn't connect to host%S
55* Closing connection #0
56
57temp stream (leak):
58About to rewind!
59* About to connect() to 127.0.0.1 port 37349%r.*%r
60*   Trying 127.0.0.1...%A* Connection refused
61* couldn't connect to host%S
62* Closing connection #0
63
64memory stream (leak):
65About to rewind!
66* About to connect() to 127.0.0.1 port 37349%r.*%r
67*   Trying 127.0.0.1...%A* Connection refused
68* couldn't connect to host%S
69* Closing connection #0
70
71Done.
72