2

Related:

I'm looking for a combination of methods described in the other topics. I probably need to read the file (from URL) in small chunks, pipe these into the STDIN of a proc_open zip command, grab output and flush this towards the client.

What I need to do:

  • Read a file stream from an URL from a storage server
  • Zip it on the fly on a webserver
  • Offer it as a download to the web browser, using content-disposition with unknown size (it's a stream after all).

What I can't do:

  • Store files on the webserver
  • Run code on the storage server
  • Use a lot of memory
  • Let the client wait for the download

So the flushing of data needs to start while remote chunk-reading is still in progress.

Would this be possible in PHP? I feel like this would be much easier in languages which offer more callback/async functionality, but I'm stuck with PHP in this situation.

Any examples or some rough code would be very welcome!

Community
  • 1
  • 1
okdewit
  • 1,753
  • 20
  • 28

1 Answers1

0

It's not PHP, but this project does exactly what you're looking for. You can host it as a standalone server and call it from php:

https://github.com/scosman/zipstreamer

scosman
  • 1,896
  • 13
  • 25