ID:               49517
 Updated by:       [email protected]
 Reported By:      niraj at bhawnani dot name
-Status:           Open
+Status:           Verified
 Bug Type:         Filesystem function related
 Operating System: Windows Vista
 PHP Version:      5.3.0
 New Comment:

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.
?>


Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to