我的网站是使用纯PHP和MySQL开发的流式传输视频时"请尝试此链接"此处
如果你点击任何一个名为"ماهد"的按钮,网站将不会像导航到任何其他页面一样响应任何其他请求。
这是我的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();