Downloading BIG files: fread() vs file_get_contents()
Posted: Wed Mar 03, 2010 4:32 pm
Hi
I am downloading BIG files: +20 MBytes
Both of the following code samples work.
My question is: At what point I should NOT consider using file_get_contents() sample and I should using fread() sample instead?
The PHP documentation states that fread() has a maximum read capability of 8192 bytes.
But the PHP documentation does not state for file_get_contents() what is its maximum read capability.
Using file_get_contents() to download BIG file
Using fread() to download BIG file
Thanks
Jeff in Seattle
I am downloading BIG files: +20 MBytes
Both of the following code samples work.
My question is: At what point I should NOT consider using file_get_contents() sample and I should using fread() sample instead?
The PHP documentation states that fread() has a maximum read capability of 8192 bytes.
But the PHP documentation does not state for file_get_contents() what is its maximum read capability.
Using file_get_contents() to download BIG file
Code: Select all
$fpOut = fopen($strFilePath, "w+b");
$strContent = file_get_contents($strBlobURL);
if ( $strContent !== false ) {
fwrite($fpOut, $strContent);
}
fclose($fpOut);Code: Select all
$fpWrite = @fopen($strFilePath, "w+b");
$fpRead = @fopen($strBlobURL, "rb");
while (!feof($fpRead)) {
fwrite($fpWrite, fread($fpRead, 8192));
}
fclose($fpWrite);
fclose($fpRead);Jeff in Seattle