流视频 - 致命错误:允许的内存耗尽 - memory_limit确定

时间:2017-12-06 12:37:55

标签: php iis video-streaming memory-limit

我在IIS 10和PHP 7上有一个网站,我想提供最多1 GB的视频

在IIS上我设置

Maximum allowed content length: 1073741824

在php.ini中我设置了

post_max_size = 1024M
upload_max_filesize = 1024M

并且因为php文档说:

  

“一般来说,memory_limit应该大于post_max_size”

memory_limit = 1025M

上传没问题,但在这一行上读取0.5 GB的视频:

$fp=fopen($file,"r"); while(!feof($fp)) {echo fread($fp,filesize($file)); flush();} fclose($fp);

我得到了

Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 539267072 bytes)

虽然phpinfo()返回正确的值,但对于调试我也尝试了

ini_set('memory_limit',-1);

但没有改变

为什么我收到此错误?

必须使用所有这些内存来投放视频吗?

有更好的流媒体视频方式吗?

由于

更新1

代码

<?php
ini_set('display_errors', 'On'); error_reporting(E_ALL);
$file="video.mp4";
if(file_exists($file))
{

    header('Content-Description: File Transfer');
    header('Content-Type: video/mp4');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Length: '.filesize($file));
    ob_clean();
    flush();
    $fp=fopen($file,"r"); while(!feof($fp)) {echo fread($fp,filesize($file)); flush();} fclose($fp);
    exit;
}
?>

0 个答案:

没有答案