Web Hosting Talk







View Full Version : PHP script - downloading huge files


taken
06-22-2009, 10:40 AM
1. Is this the correct way (efficiency) to do this? (on WinXP box, local server, PHP command line) (no, I can't use the win32 ports of wget, curl, etc)

2. 8192 (8Kb) is OK? what about a larger 1MB buffer?

3. Download speed is not a problem, but these scripts should work 24x7 for 2 or 3 days. Is this bad for the 1TB WD hard disk? fwrite=automatic buffering (by WinXP)?




//$url1="http://remote-server/3GB-remote-file.binary";
$handler = get_handler($url1);

if (!$g = fopen($local_file, 'a'))
{
exit;
}

while ($buffer = fread($handler, 8192))
{
fwrite($g, $buffer);
}
fclose($g);

HivelocityDD
06-22-2009, 07:34 PM
Its okay. But if you are using java you can implement threading to handle this in a better way.

Unquantifiable
06-22-2009, 07:47 PM
Need to see the code of get_handler()
Looks like it's loading the entire file into ram.

If it's not, a 8k buffer sounds about right.

You will also need to modify the loop as follows:

while (!feof($handler))
{
$buffer = fread($handler, 8192);
fwrite($g, $buffer);
}