note 82946 added to ref.curl
| From: | PeterX dot at osu1 dot php dot net | Date: | Sat, 03 May 2008 02:44:23 +0000 |
| Subject: | note 82946 added to ref.curl | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139013@lists.php.net to get a copy of this message | ||
Although it has been noted that cURL outperforms both file_get_contents and fopen when it comes to
getting a file over a HTTP link, the disadvantage of cURL is that it has no way of only reading a
part of a page at a time.
For example, the following code is likely to generate a memory limit error:
<?php
$ch = curl_init("http://www.example.com/reallybigfile.tar.gz");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$output = curl_exec($ch);
$fh = fopen("out.tar.gz", 'w');
fwrite($fh, $output);
fclose($fh);
?>
While this, on the other hand, wouldn't
<?php
$hostfile = fopen("http://www.example.com/reallybigfile.tar.gz",
'r');
$fh = fopen("out.tar.gz", 'w');
while (!feof($hostfile)) {
$output = fread($hostfile, 8192);
fwrite($fh, $output);
}
fclose($hostfile);
fclose($fh);
?>
----
Server IP: 208.69.120.35
Probable Submitter: 99.226.244.18
----
Manual Page -- http://www.php.net/manual/en/ref.curl.php
Edit -- https://master.php.net/note/edit/82946
Del: integrated -- https://master.php.net/note/delete/82946/integrated
Del: useless -- https://master.php.net/note/delete/82946/useless
Del: bad code -- https://master.php.net/note/delete/82946/bad+code
Del: spam -- https://master.php.net/note/delete/82946/spam
Del: non-english -- https://master.php.net/note/delete/82946/non-english
Del: in docs -- https://master.php.net/note/delete/82946/in+docs
Del: other reasons-- https://master.php.net/note/delete/82946
Reject -- https://master.php.net/note/reject/82946
Search -- https://master.php.net/manage/user-notes.php