ID: 49517
Updated by: iliaa@php.net
Reported By: niraj at bhawnani dot name
-Status: Verified
+Status: Closed
Bug Type: cURL related
Operating System: *
PHP Version: 5.*, 6 (2009-09-09)
New Comment:
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
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2009-09-30 02:34:17] svn@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=288973
Log: Fixed bug #49517 (cURL's CURLOPT_FILE prevents file from being
deleted after fclose).
------------------------------------------------------------------------
[2009-09-10 08:00:46] sjoerd@php.net
Could reproduce.
<?php
$filename = tempnam('/tmp', 'bug49517');
$fp = fopen($filename, 'w');
$curl = curl_init();
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_close($curl);
fclose($fp);
var_dump(is_resource($fp)); // expected: false, because $fp is closed.
?>
------------------------------------------------------------------------
[2009-09-10 06:27:39] niraj at bhawnani dot name
It is definitely related to Bug #48676, if I fclose($fp) twice, it
works.
Here's the same code with a workaround, that makes the unlink work
fine:
<?php
$filename = 'tempfile';
$fp = fopen($filename, 'w');
if (!$fp)
exit("Failed to open file for writing");
$curl = curl_init('http://bugs.php.net/gifs/logo-bug.gif');
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); // 10 sec
curl_setopt($curl, CURLOPT_TIMEOUT, 600); // 10 mins
curl_exec($curl);
curl_close($curl);
fclose($fp);
if (is_resource($fp))
fclose($fp);
unlink($filename);
?>
------------------------------------------------------------------------
[2009-09-10 06:16:30] niraj at bhawnani dot name
Description:
------------
I spent hours debugging some code I'd written that wasn't working only
to find that cURL is behaving strangely. I've taken the minimal parts of
that code and put it in this bug report.
Basically, if you open a file with fopen, fclose it and then unlink it,
it works fine. But if between fopen and fclose, you give the file handle
to cURL to do some writing into the file, then the unlink fails. Why
this is happening is beyond me. I think it may be related to Bug #48676
I have not had the opportunity to test this on Linux, so I don't know
if it's Windows-only.
Reproduce code:
---------------
<?php
$filename = 'tempfile';
$fp = fopen($filename, 'w');
if (!$fp)
exit("Failed to open file for writing");
$curl = curl_init('http://bugs.php.net/gifs/logo-bug.gif');
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); // 10 sec
curl_setopt($curl, CURLOPT_TIMEOUT, 600); // 10 mins
curl_exec($curl);
curl_close($curl);
fclose($fp);
unlink($filename);
?>
Expected result:
----------------
No errors, file unlinks successfully.
Actual result:
--------------
Warning: unlink(tempfile) [function.unlink]: Permission denied in
C:\...\blah.php on line 14
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49517&edit=1