PHP:在中间服务器上动态压缩文件流,而不存储(太多)数据 [英] PHP: Zip a file stream on the fly on an intermediate server, without storing (too much) data

查看:31
本文介绍了PHP:在中间服务器上动态压缩文件流,而不存储(太多)数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关:

我正在寻找其他主题中描述的方法的组合.我可能需要读取文件(从 URL)小块,将它们通过管道传输到 proc_open zip 命令的 STDIN,抓取输出并将其刷新到客户端.

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.

我需要做什么:

  • 从存储服务器的 URL 读取文件流
  • 在网络服务器上即时压缩
  • 使用未知大小的内容配置将其作为下载提供给网络浏览器(毕竟它是一个流).

我不能做什么:

  • 在网络服务器上存储文件
  • 在存储服务器上运行代码
  • 占用大量内存
  • 让客户端等待下载

因此需要在远程块读取仍在进行时开始刷新数据.

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

这在 PHP 中可行吗?我觉得这在提供更多回调/异步功能的语言中会容易得多,但在这种情况下我坚持使用 PHP.

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!

推荐答案

它不是 PHP,但该项目正是您正在寻找的.您可以将其作为独立服务器托管并从 php 调用它:

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

这篇关于PHP:在中间服务器上动态压缩文件流,而不存储(太多)数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆