Time till start download
The startingtime depends (mainly) on:
- Time it takes to run the PHP code (this should take little time)
- The time it takes before the first data is send
The latter one is the main contributor, you want to send (some) data as fast as you can. If you echo a file_get_contents()
of a file, you would have to wait untill all the data is send to the browser (essentially the whole download it will blank, and at the end the whole file will be complete in 1 go). What you want is to send it in chucks, send small pieces real fast.
Examplecode which sends 1024 bytes per itteration:
// OPENING THE FILE
$file = fopen($filepath, "r");
$bufferlength = 1024;
while (!feof($file)){
// READ A BUFFER SIZE OF THE FILE
$buffer = fread($file, $bufferlength);
echo $buffer;
$buffer = "";
flush(); // THIS IS ESSENTIAL FOR LARGE DOWNLOADS
}
fclose($fp);
The max speed here is: $bufferlength*(itterations in 1 sec) bytes/sec
.
You could use algorithms to make it send small chunks in the beginning, increasing in size the further it progresses.
Time to complete download
This is influenced by the code above, but that will be fast enough for 99% of the cases.
The main cause here is bandwidth. Cheap hosts are not premium hosts, you don't get much bandwidth. The speed at which you can upload is limited, and if multiple users want to download something, this will get shared amongst them.