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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/10/12 m.hasibuan <magda.hasibuan@xxxxxxxxxxx>:
> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux