This article describes how to limit the download speed of php. For more information, see
The Code is as follows:
// Local file that shocould be sent to the client
$ Local_file = 'test-file.zip ';
// Filename that the user gets as default
$ Download_file = 'your-download-name.zip ';
// Set the download rate limit (=> 20, 5 kb/s)
$ Download_rate = 20.5;
If (file_exists ($ local_file) & is_file ($ local_file )){
// Send headers
Header ('cache-control: private ');
Header ('content-Type: application/octet-stream ');
Header ('content-Length: '. filesize ($ local_file ));
Header ('content-Disposition: filename = '. $ download_file );
// Flush content
Flush ();
// Open file stream
$ File = fopen ($ local_file, "r ");
While (! Feof ($ file )){
// Send the current file part to the browser
Print fread ($ file, round ($ download_rate * 1024 ));
// Flush the content to the browser
Flush ();
// Sleep one second
Sleep (1 );
}
// Close file stream
Fclose ($ file );
}
Else {
Die ('error: The file'. $ local_file. 'does not exist! ');
}