我正在嘗試創建php流應用程序。 問題是我不能讓兩個用戶在同一時間連接,因爲他們支付了它,所以如果他們分享流是無用的。如何檢測用戶是否中止了連接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();`
Tnx,我不知道這是答案,但我會研究它! – user1606732