Manipulate an Archive in memory with PHP (without creating a temporary file on disk)

后端 未结 5 1072
太阳男子
太阳男子 2020-11-27 05:06

I am trying to generate an archive on-the-fly in PHP and send it to the user immediately (without saving it). I figured that there would be no need to create a file on disk

5条回答
  •  爱一瞬间的悲伤
    2020-11-27 05:29

    Is there really a performance issue here, or does it just offend your sense of rightness? A lot of processes write temporary files and delete them, and often they never hit the disk due to caching.

    A tempfile is automatically deleted when closed. That's it's nature.

    There are only two ways I can think of to create a zip file in memory and serve it and both are probably more trouble than they are worth.

    • use a ram disk.
    • modify the ziparchive class to add a method that does everything the close() method does, except actually close the file. (Or add a leave-open parameter to close()).
      This might not even be possible depending on the underlying C libraries.

提交回复
热议问题