How can you limit download speed in a PHP script?

To limit download speed in a PHP script, you can use the `flush()` and `usleep()` functions to control the rate at which data is sent to the client. By sending data in small chunks with delays in between, you can effectively limit the download speed.

<?php
$file = 'path_to_your_file.ext';
$chunkSize = 1024; // 1KB chunks
$delay = 50000; // 50 milliseconds delay between chunks

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');

$handle = fopen($file, 'rb');
while (!feof($handle)) {
    echo fread($handle, $chunkSize);
    flush();
    usleep($delay);
}
fclose($handle);
?>