When I first built the download proxy for ramrom.io , I did the obvious thing. PHP has a function called readfile() . You give it a URL or a path, it reads the whole file and sends it to the browser. One line, done. It worked perfectly in testing β until someone pasted a video that was a few hundred megabytes.
The problem is how readfile() actually works. It loads the whole file into memory before it sends anything. On a local machine with plenty of RAM, nobody notices. On a shared hosting plan, the PHP process is capped at a modest memory limit β mine is 128MB β and a single 300MB video blows straight past it. The visitor gets a blank page or a half-finished file, and the server logs a fatal error that tells me nothing useful.
So I rewrote the proxy to stream in chunks.β¦