我正在尝试创建 php 流应用程序。问题是我不能允许两个用户同时连接,因为他们正在为此付费,所以如果他们共享流,那将毫无用处。
所以我的解决方案是在我的 MySQL 数据库中添加一行,如果用户使用 1 登录并且当用户停止/取消流记录将设置回 0,我将在其中记录。这就是我无法检测到的问题当用户中止连接时。我尝试了一切,我认为:ignore_user_abort(true), while(!connection_aborted){readfile($stream)}...
我有多个流文件,但我将把我认为最接近解决方案的一个放在这里。O 还有一件事它工作了一段时间,而我没有使用任何类型的动态流/用户名/密码。所以这里是文件:
<?php
require "../general/bootstrap.php"; // Include bootstrap
require "../general/error.php"; // Comertials when error
session_write_close();
ignore_user_abort(TRUE);
set_time_limit(0);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in history
header("Content-Transfer-Encoding: binary");
header("Cache-control: no-cache");
header('Pragma: no-cache');
if (count($items) != 3) {
if (isset($items[1]) && !empty($items[1])) {
$username = $items[1];
} else {
$username = null;
}
error("Missing one or more arguments(tv, username, password)!", $username);
}
$channel = (string) $items[0];
$username = (string) $items[1];
$password = (string) $items[2];
if (stream::channel_exists($channel)) {
if (stream::channel_is_tv($channel)) {
header('Content-Disposition: attachment; filename="stream.xspf"');
} else {
header('Content-Disposition: attachment; filename="stream.m3u"');
}
} else {
header('Content-Disposition: attachment; filename="stream.xspf"');
}
if (!stream::user_has_channel($username, $channel)) {
error("User has requested channel '$channel' that it doesn't have!", $username);
}
if (!user::login($username, $password)) {
error("Login failed! - probably because of trying to log in from 2 places at the same time or invalid username/password combination!", $username);
}
if (!isset($stream))
$stream = stream::get_channel_stream($channel); // returns http://xxx.xxx.xxx.xxx/channel
function flush_buffers() {
ob_end_flush();
ob_flush();
flush();
//ob_start();
fastcgi_finish_request();
}
// STREAM START
stream:
while(!connection_aborted() && user::is_enabled($username)) {
readfile($stream);
flush_buffers();
}
//STREAM END
sleep(10);
if(!connection_aborted()){
goto stream;
}
user::logout($username);
exit();`