Re: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
2009/10/12 m.hasibuan magda.hasib...@yahoo.co.uk: Newbie question. I need to download a very large amount of xml data from a site using CURL. How to bypass (pipe) curl_exec return value directly to a file, without using memory allocation? set_time_limit(0); $ch = curl_init($siteURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $mixed = curl_exec($ch); How to set/pipe $mixed as a (disk) file, so that data returned by curl_exec is directly saved to the disk-file, and not involving memory allocation? Thank you. Use the CURLOPT_FILE option to set the output to write to the file handle given by the option's value (which must be a writable file handle). For instance: $ch = curl_init($url); $fp = fopen('/tmp/curl.out', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); Error checking etc. is of course left up to you. :) Good luck, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
I guess this should work set_time_limit(0); $ch = curl_init($siteURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_FILE, 'stream.bin'); curl_exec($ch); Regards From: magda.hasib...@yahoo.co.uk To: php-general@lists.php.net Date: Tue, 13 Oct 2009 11:01:04 +0700 Subject: [PHP] How to bypass (pipe) curl_exec return value directly to a file? Newbie question. I need to download a very large amount of xml data from a site using CURL. How to bypass (pipe) curl_exec return value directly to a file, without using memory allocation? set_time_limit(0); $ch = curl_init($siteURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $mixed = curl_exec($ch); How to set/pipe $mixed as a (disk) file, so that data returned by curl_exec is directly saved to the disk-file, and not involving memory allocation? Thank you. -PHP 5 -Windows XP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Windows Live: Make it easier for your friends to see what you’re up to on Facebook. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009
RE: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
$ch = curl_init($url); $fp = fopen('/tmp/curl.out', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); Error checking etc. is of course left up to you. :) oops, I sent directly the file name. Let me reformulate the code then: set_time_limit(0); $fp = fopen('stream.bin', 'wb'); $ch = curl_init($siteURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); fclose($fp); Apologize I did not test it before. Regards _ Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
Re: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
2009/10/13 Andrea Giammarchi an_...@hotmail.com: $ch = curl_init($url); $fp = fopen('/tmp/curl.out', 'w'); curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); Error checking etc. is of course left up to you. :) oops, I sent directly the file name. Let me reformulate the code then: set_time_limit(0); $fp = fopen('stream.bin', 'wb'); $ch = curl_init($siteURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); If you're re-using a curl handle then it may be a good idea to set these explicitly. However, these are also the default values so it's not really necessary to set them for a new handle. You're right that it's a good idea to include the 'b' in the fopen() mode. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); I wouldn't recommend setting this to 0 unless you're very sure that the connection will succeed; otherwise, your script will hang indefinitely waiting for the connection to be made. Regards, Torben curl_setopt($ch, CURLOPT_FILE, $fp); curl_exec($ch); fclose($fp); Apologize I did not test it before. Regards Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); I wouldn't recommend setting this to 0 unless you're very sure that the connection will succeed; otherwise, your script will hang indefinitely waiting for the connection to be made. agreed, it's just he set timeout to zero so I guess he meant the curl connection as well otherwise it does not make sense to set the timeout to 0 if curl has 10 seconds timeout :-) Regards _ Windows Live Hotmail: Your friends can get your Facebook updates, right from Hotmail®. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_4:092009
Re: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
2009/10/13 Andrea Giammarchi an_...@hotmail.com: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); I wouldn't recommend setting this to 0 unless you're very sure that the connection will succeed; otherwise, your script will hang indefinitely waiting for the connection to be made. agreed, it's just he set timeout to zero so I guess he meant the curl connection as well otherwise it does not make sense to set the timeout to 0 if curl has 10 seconds timeout :-) Regards If he wants to download a very large file then it would make sense to set_time_limit(0) but leave the curl connect timeout enabled; he wouldn't want the PHP script timing out partway through a large download. :) The curl timeout isn't for the transfer; just for making the connection. Regards, Torben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] How to bypass (pipe) curl_exec return value directly to a file?
uhm, right, I should have better explain that option ... still, if timelimit is 0, I guess connection timeout matters, maybe I am wrong. Thanks. Regards Date: Tue, 13 Oct 2009 11:31:00 -0700 Subject: Re: [PHP] How to bypass (pipe) curl_exec return value directly to a file? From: larstor...@gmail.com To: an_...@hotmail.com CC: magda.hasib...@yahoo.co.uk; php-general@lists.php.net 2009/10/13 Andrea Giammarchi an_...@hotmail.com: curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); I wouldn't recommend setting this to 0 unless you're very sure that the connection will succeed; otherwise, your script will hang indefinitely waiting for the connection to be made. agreed, it's just he set timeout to zero so I guess he meant the curl connection as well otherwise it does not make sense to set the timeout to 0 if curl has 10 seconds timeout :-) Regards If he wants to download a very large file then it would make sense to set_time_limit(0) but leave the curl connect timeout enabled; he wouldn't want the PHP script timing out partway through a large download. :) The curl timeout isn't for the transfer; just for making the connection. Regards, Torben _ Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail you. http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010