Fastest way to read from an url?
| From: | Stefan Rusterholz | Date: | Wed, 23 Jan 2002 15:30:16 +0000 |
| Subject: | Fastest way to read from an url? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-81693@lists.php.net to get a copy of this message | ||
Hi
I got following problem: I have to open an url (with PHP of course) and read it's content into
a variable. The URL contains binary data from about 1MB to 5MB.
Wenn I open the URL with the Browser (with "save link to disk") I get an approximatly
speed of 1MB/s (it's on an intranet) but doing the same with PHP, PHP only reaches speeds about
200KB/s.
I use following construct:
$filecontent = "";
if (!$fc = fopen('http://remotehost/'.$filepath,'b')){
trigger_error("fopen failed on ".'http://remotehost/'.$filepath, E_USER_ERROR); }
while (!feof ($fc)) {
$buffer = fread($fc, $chunk_size);
$filecontent .= $buffer;
}
fclose ($fc);
$chunk_size is set to 16*1024 (=>16Kb)
I experimented a bit with the chunksize and at this size it seems to be at its fastest, but still 5
times slower than it should be possible. How can I gain max. speed?
TIA & best regards
Stefan Rusterholz