|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52820 curl doesn't write to php://temp or /memory
Submitted: 2010-09-12 02:05 UTC Modified: 2010-11-15 19:23 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: klawd+phpbugs at kamundo dot de Assigned: cataphract (profile)
Status: Closed Package: Streams related
PHP Version: 5.3.3 OS: Ubuntu
Private report: No CVE-ID: None
 [2010-09-12 02:05 UTC] klawd+phpbugs at kamundo dot de
Setting CURLOPT_STDERR to fopen('php://output', 'w') will write curl debug output.

One would await that setting it to fopen('php://memory', 'w') would store it in the memory and it would be available after a rewind. That is not the case, instead, a warning is raised:

Warning: curl_setopt(): supplied argument is not a valid File-Handle resource in

is php://output a valid file handle resource?

This is very confusing and it should be possible to store the output in the memory.

Test script:
curl_setopt($handle, CURLOPT_STDERR, fopen('php://output'));
curl_setopt($handle, CURLOPT_STDERR, $output=fopen('php://temp'));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-12 13:21 UTC]
-Status: Open +Status: Feedback
 [2010-09-12 13:21 UTC]
Your description and your test script don't match. The first mentions "php://memory", the script uses "php://temp".

Additionally, you don't specify open modes in the test script.

Seeing the source code, there's a small error in that persistent resources are not accepted (ZEND_FETCH_RESOURCE2 should have been used), but it should not cause the problem you're describing.

Please fix the problems with your bug report.
 [2010-09-12 13:37 UTC]
Anyway, this works here:

curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_STDERR, $o = fopen('php://temp', "w+"));
echo "output: ".stream_get_contents($o);

php://memory doesn't work because that stream cannot be cast into a stdio FILE, which curl apparently requires.
 [2010-09-12 19:31 UTC] klawd+phpbugs at kamundo dot de
Fixed test script, now with

curl_setopt($handle, CURLOPT_VERBOSE, true);
curl_setopt($handle, CURLOPT_STDERR, fopen('php://output', "w+"));
curl_setopt($handle, CURLOPT_STDERR, $output=fopen('php://temp', "w+"));

Please use var_dump. You will see that it's empty. There should be two outputs:
- the one directly written to STDOUT
- one with string(n) and wrapped by var_dump's quotes
but the latter is empty:
string(0) ""

I tried both memory and temp
 [2010-09-12 21:37 UTC]
-Status: Feedback +Status: Verified
 [2010-09-12 21:37 UTC]

The problem was that I was testing on Windows, where this works.

I've just tested in Ubuntu, and indeed the string was empty there. However, I didn't get the warning you've described.
 [2010-09-12 21:49 UTC] klawd+phpbugs at kamundo dot de
I didn't get the warning in my latest run. It could stem from the missing open modes which would be weird but possible.
 [2010-09-13 17:22 UTC]
-Package: Sockets related +Package: Streams related
 [2010-11-15 06:08 UTC]
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: cataphract
 [2010-11-15 06:08 UTC]
I've identified the problem and I will commit a fix tomorrow.
 [2010-11-15 19:22 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed bug #52820 (writes to fopencookie FILE* not commited when seeking the
 [2010-11-15 19:23 UTC]
-Status: Assigned +Status: Closed
 [2010-11-15 19:23 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2010-11-18 22:44 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed borked test bug52820.phpt.
- Synced htmlentities17.phpt with trunk; there's no &amp;wreath; entity
  in HTML 4.01.
 [2011-03-20 23:15 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed SKIPIF section of bug52820.phpt.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Oct 02 19:01:25 2023 UTC