是否可以将来自Zend_Service_Amazon_S3 (http://framework.zend.com/manual/en/zend.service.amazon.s3.html#zend.service.amazon.s3.streaming)的流传输到浏览器?
我正在寻找像readfile (http://www.php.net/manual/en/function.readfile.php)这样的东西,但是我想要一个流,而不是一个文件作为输入。
发布于 2011-11-09 01:36:12
可以,只需将其复制到STDOUT即可,它是“一个只写流,允许您以与print()和echo()相同的方式写入输出缓冲区机制”(manual)。
stream_copy_to_stream($response->getStream(), STDOUT);发布于 2017-03-07 02:27:25
一种类似的解决方案是使用
fpassthru($response->getStream())作为PHP manual clearly states,STDOUT仅用于CLI SAPI。但即使在CLI上,它也不能在这样的上下文中使用
php < script.php在这种情况下(例如,如果您尝试在php-fpm中使用STDOUT ),stream_copy_to_stream()会出现以下错误
PHP Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in $FILE on line $LINE
PHP Warning: stream_copy_to_stream() expects parameter 2 to be resource, string given in $FILE on line $LINE一旦使用fpassthru(),这个问题就会消失。
我没有在AWS上测试它,但我非常确定它在那里也是有效的。
https://stackoverflow.com/questions/8054610
复制相似问题