Php fastCGI在多次刷新页面时崩溃,出现500错误

Php fastCGI在多次刷新页面时崩溃,出现500错误,php,iis,fastcgi,Php,Iis,Fastcgi,我使用以下代码在localhost(Windows IIS)中使用PHP流式处理mp4文件。当我多次单击seekbar或频繁刷新页面时,页面崩溃,错误为500: FastCGI进程最近经常失败。请稍后重试该请求 我不确定这是一个资源使用者代码,还是fastCGI模块有限制,或者是什么?任何帮助都将不胜感激。根据错误消息,崩溃的进程是php-cgi.exe。您可以尝试在FASTCGI配置中最大化“Instance MaxRequest”。IIS root>FastCGI设置,选择php-cgi

我使用以下代码在localhost(Windows IIS)中使用PHP流式处理mp4文件。当我多次单击seekbar或频繁刷新页面时,页面崩溃,错误为500:

FastCGI进程最近经常失败。请稍后重试该请求


我不确定这是一个资源使用者代码,还是fastCGI模块有限制,或者是什么?任何帮助都将不胜感激。

根据错误消息,崩溃的进程是php-cgi.exe。您可以尝试在FASTCGI配置中最大化“Instance MaxRequest”。IIS root>FastCGI设置,选择php-cgi.exe,然后编辑并增加实例MaxRequests。
<?php
$file = 'test.mp4';
$fp = @fopen($file, 'rb');
$size = filesize($file); // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
header('Content-type: video/mp4');
//header("Accept-Ranges: 0-$length");
header("Accept-Ranges: bytes");
if (isset($_SERVER['HTTP_RANGE'])) {
    $c_start = $start;
    $c_end = $end;
    list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
    if (strpos($range, ',') !== false) {
        header('HTTP/1.1 416 Requested Range Not Satisfiable');
        header("Content-Range: bytes $start-$end/$size");
        exit;
    }
    
    if ($range == '-') {
        $c_start = $size - substr($range, 1);
    }else{
        $range = explode('-', $range);
        $c_start = $range[0];
        $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $size;
    }
    $c_end = ($c_end > $end) ? $end : $c_end;
    
    if ($c_start > $c_end || $c_start > $size - 1 || $c_end >= $size) {
        header('HTTP/1.1 416 Requested Range Not Satisfiable');
        header("Content-Range: bytes $start-$end/$size");
        exit;
    }
    $start = $c_start;
    $end = $c_end;
    $length = $end - $start + 1;
    fseek($fp, $start);
    header('HTTP/1.1 206 Partial Content');
}
header("Content-Range: bytes $start-$end/$size");
header("Content-Length: ".$length);
$buffer = 1024 * 8;
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
    if ($p + $buffer > $end) {
        $buffer = $end - $p + 1;
    }
    set_time_limit(0);
    echo fread($fp, $buffer);
    flush();
}
fclose($fp);
exit();
?>