Re: How to bypass (pipe) curl_exec return value directly to a file?

From: Date: Tue, 13 Oct 2009 15:34:54 +0000
Subject: Re: How to bypass (pipe) curl_exec return value directly to a file?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-298882@lists.php.net to get a copy of this message
2009/10/13 Andrea Giammarchi <an_red@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.

« previous php.general (#298882) next »