[英]Php Session Lock Wait timeout
我的情況更糟。
我有一個代理網站,我的共享主機帳戶最多允許25個進程進入我的帳戶。 我剛剛開始使用會話鎖對來自單個用戶的多個請求進行排隊。 這意味着,如果已經有一個請求或用戶已經在流式傳輸視頻,那么他的下一個請求將一直等到流式傳輸結束。 (而且我不得不采用這種方法,因為用戶一次開始使用下載程序下載多個視頻。更糟糕的是,下載程序通常要求一次下載4次。這樣,只有一個用戶在使用我的所有資源。 )
當前的問題是,正在等待的第二個請求也需要一個單獨的過程。 這樣,只有兩個用戶可以達到我的最大25個進程限制。
我正在PHP配置中尋找類似於“會話鎖定等待”的超時時間,在那之后(例如:20秒),PHP應該關閉任何消息或其他內容的連接。 因此,我們可以釋放剛剛等待的過程。
還請告訴我是否有人對此有任何Linux解決方案。
是否有任何Linux命令可以使所有運行php scrip的進程都處於等待模式?
提前致謝。
對於問這個問題的人來說可能為時已晚,但是可以在腳本結束之前使用函數session_write_close()解鎖會話。 您可以執行以下操作:
<?php
session_start();
// ... use and/or update session data
session_write_close();
// begin streaming
header("Content-Type: foo/bar");
$f=fopen("hundred-meg-video.mp4","rb");
fpassthru($f);
fclose($f);
?>
或者,您可以在流端重新打開會話。 我們使用它來限制每用戶並發下載的數量:
<?php
$limit=4;
session_start();
if ($_SESSION["concurrent_downloads"]>$limit) {
header("HTTP/1.1 500 Internal Server Error");
echo "too many concurrent downloads";
die;
}
ignore_user_abort(1); // if the user aborts the script, we still want it to continue running on the server
// otherwise the $_SESSION["concurrent_downloads"] would not decrease at its end
$_SESSION["concurrent_downloads"]++;
session_write_close();
// begin streaming
header("Content-Type: foo/bar");
$f=fopen("hundred-meg-video.mp4","rb");
fpassthru($f);
fclose($f);
// resume using session
@session_start(); // @ used to suppress "headers already sent" message
$_SESSION["concurrent_downloads"]--;
?>
找不到任何PHP選項“會話鎖定超時”
要列出訪問的會話文件,請嘗試lsof |grep session
你應該得到這樣的輸出
16uW的行是鎖定實際會話文件的PHP進程
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.