The fread
method is insane.
- It wastes network and CPU.
- It will certainly introduce delay (proportional to how far into the file you want to seek)
- It can easily kill your server the way you've implemented: Doing
fread(..$length)
means the program will use $length of RAM. If you do a bunch of these at once, your server will probably go out to lunch.
It is perfectly reasonable to do streaming via range headers. Your current library may not support it, but it should be easy to add (i.e. pass the range header to fopen
somehow)