After some conversations with Rasmus on IRC i've come up with the following patch:

http://ilia.ws/patch/curl.txt

This basically forces flush() on the header & output streams right after curl_exec(), this ensures that the data retrieved by curl is synched to disk. The patch is also self contained to curl so no external elements are affected by the patch.

Ilia Alshanetsky




On 26-Jun-09, at 8:24 PM, Rasmus Lerdorf wrote:

Just to keep the list in synch with the irc discussion.  I pointed out
that this is only half of the fix.  The refcount still prevents fclose
from flushing the data, so if you do:

$url = 'http://slowgeek.com/test.xml';
$cfile = 'out.xml';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp = fopen($cfile,'w'));
$status = curl_exec($ch);
fclose($fp);
$data = file_get_contents($cfile);
var_dump($data);  // 0 bytes here
curl_close($ch);
$data = file_get_contents($cfile);
var_dump($data);  // full contents here

I still think we need to look at doing a flush on an fclose which
doesn't reach the stream destructor due to refcount issues.

Can anybody think of any side-effects of a flush on a stream close?

-Rasmus


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to