|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48207 CURLOPT_FILE behaves unexpectedly with invalid file handle
Submitted: 2009-05-09 14:01 UTC Modified: 2009-05-21 12:53 UTC
From: mark at dynom dot nl Assigned:
Status: Closed Package: cURL related
PHP Version: 5.*, 6CVS (2009-05-09) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
36 - 8 = ?
Subscribe to this entry?

 [2009-05-09 14:01 UTC] mark at dynom dot nl
The option 'CURLOPT_FILE' takes a file handle as argument, however when you open the file read-only. cURL *silently* fails and downloads only 1 successful iteration of data.

This *only* happens when CURLOPT_RETURNTRANSFER is not defined, since that disables the 'CURLOPT_FILE' feature.

It's expected that some sort of warning/error is raised, just like when a write flag is set when the file is not writable. When the latter happens, cURL falls back on CURLOPT_RETURNTRANSFER = false.

Reproduce code:
error_reporting( E_ALL );

$ch = curl_init('');

$fp = fopen("/tmp/fubar", "r"); // Opening 'fubar' with the incorrect readonly flag
curl_setopt($ch, CURLOPT_FILE, $fp);

// Debug
$info = curl_getinfo($ch);

if ($info['size_download'] !== $info["download_content_length"]) {
        echo 'fail';
} else {
        echo 'works';


Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-09 14:03 UTC] mark at dynom dot nl
Sorry, the expected result is not 'works', it's an error being raised.
 [2009-05-10 08:17 UTC] mark at dynom dot nl
Tried it, but I don't get a notice, warning or error.
I'm testing with this roughly-edged test case:
 [2009-05-10 17:04 UTC]
Thanks. That means it exists also in PHP_5_2. (That's why I asked..)
 [2009-05-21 12:53 UTC]
This bug has been fixed in CVS.

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.

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Dec 05 00:01:26 2023 UTC