Limit download speed using PHP

The reason your download stops after 5MB is because it takes over 60 seconds to download 5MB at 80KB/s. Most of those “speed limiter” scripts use sleep() to pause for a while after sending a chunk, resume, send another chunk, and pause again. But PHP will automatically terminate a script if it’s been running for a minute or more. When that happens, your download stops.

You can use set_time_limit() to prevent your script from being terminated, but some web hosts will not allow you to do this. In that case you’re out of luck.

Leave a Comment