PHP 流式传输视频时网站无响应

PHP Website not responding while streaming a video

我的网站是使用纯 PHP 和 MySQL 开发的 在播放视频时 "Please try this link" Here

如果您单击任何名为“مشاهدو”的按钮,该网站将不会响应任何其他请求,例如导航到任何其他页面。

这是我的 Stream.php 文件的代码

<?php

session_start();
require("includes/connect.php");

set_time_limit(0);
if(isset($_GET["file"])){
    if(!isset($_GET["start"])) $_GET["start"] = 0;
    $seekPos = $_GET["start"];
    $file = htmlspecialchars($_GET["file"]);
    $fileName = basename($file);
    $file = $config["videoFilesPath"]."/".$fileName;
    if(!file_exists($file)) die("file does not exist: $file");
    $fh = fopen($file, "rb") or die("failed to open file");
    fseek($fh, 0, SEEK_END); $seek_end = ftell($fh);
    fseek($fh, $seekPos); $seek_start = ftell($fh);
    $fileSize =  $seek_end - $seek_start;
    session_cache_limiter('nocache');
    header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
    header("Pragma: no-cache");
    header("Content-Type: video/x-flv");
    //header("Content-Disposition: attachment; filename=\"" . $fileName . "\"");
    header('Content-Length: ' . $fileSize);
    if($seekPos != 0){
        print("FLV");
        print(pack('C', 1 ));
        print(pack('C', 1 ));
        print(pack('N', 9 ));
        print(pack('N', 9 ));
    }
    fseek($fh, $seekPos);
    $i=1;
    while (true){
        $var = fread($fh, 1024);
        if($var==false) break;
        echo $var;
        if(++$i%(1<<20)) ob_flush();
    }
    fclose($fh);
}

session_start() 打开并锁定会话文件,因此您必须在任何长 运行 进程之前调用 session_write_close()

session_start();
require("includes/connect.php");
session_write_close();