2013-04-28 179 views
0

我有過這種情況。Php會話鎖定等待超時

我有一個代理網站,我的共享主機帳戶允許我的帳戶最多有25個進程。 我剛剛開始使用會話鎖定從sinlge用戶的多個請求排隊。這意味着如果已經有請求或者用戶已經在流式傳輸視頻,那麼他的下一個請求將會等到流式傳輸結束。 (我不得不申請這個功能,因爲用戶已經開始使用下載器一次下載多個視頻,下載器做的更糟糕的事情是,他們通常要求單次下載4次,這樣,只有一個用戶正在使用我的所有資源。 )

目前的問題是,正在等待的第二個請求也會採取單獨的過程。這樣,只有兩個用戶可以達到我的最大進程限制。

我正在尋找PHP配置有類似會話鎖等待超時,在此之後(如:20秒),PHP應該關閉與任何消息或某事的連接。所以我們可以發佈正在等待的流程。

請告訴我,如果有人知道任何Linux解決方案。

是否有任何Linux命令來獲取所有進程運行PHP腳本和哪些處於等待模式?

在此先感謝。

+0

+1如果進程無法鎖定會話文件,PHP不應該永久掛起 – Jerem 2013-11-11 03:41:42

回答

0

找不到任何PHP選項「會話鎖定超時」

要列出訪問的會議文件,嘗試lsof |grep session

你應該得到這樣的 enter image description here

與該線輸出16uW是鎖定實際會話文件的PHP進程

1

對於提出這個問題的人來說可能太遲了,但會話可以在scr之前解鎖ipt使用函數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"]--; 
?>