简体   繁体   English

PHP会话锁定等待超时

[英]Php Session Lock Wait timeout

I have wiered situation. 我的情况更糟。

I have a proxy website and my shared hosting account allows maximum 25 processes for my account. 我有一个代理网站,我的共享主机帐户最多允许25个进程进入我的帐户。 I just started queuing multiple requests from a sinlge user using session lock. 我刚刚开始使用会话锁对来自单个用户的多个请求进行排队。 That means if there is already a request or user is already streaming a video, then his next request will wait untill the streaming ends. 这意味着,如果已经有一个请求或用户已经在流式传输视频,那么他的下一个请求将一直等到流式传输结束。 (And i had to apply this becuase users had started downloading multiple videos using downloaders at a time. The worse thing that downloader do, they normally request 4 times for a single download. In this way, only one user was using all my resources.) (而且我不得不采用这种方法,因为用户一次开始使用下载程序下载多个视频。更糟糕的是,下载程序通常要求一次下载4次。这样,只有一个用户在使用我的所有资源。 )

The current problem is, the second request which is waiting, also take a separate process. 当前的问题是,正在等待的第二个请求也需要一个单独的过程。 In this way, only two users can reach my maximum 25 processes limit. 这样,只有两个用户可以达到我的最大25个进程限制。

I am looking in PHP configuration to have something like Session Lock Wait time out, after that time (like: 20 Seconds), PHP should close the connection with any message or something. 我正在PHP配置中寻找类似于“会话锁定等待”的超时时间,在那之后(例如:20秒),PHP应该关闭任何消息或其他内容的连接。 So we can just release process which is just waiting. 因此,我们可以释放刚刚等待的过程。

Please also tell me if someone know any linux solution for this. 还请告诉我是否有人对此有任何Linux解决方案。

Is there any linux command to get all the processes running for php scrips and which are in waiting mode? 是否有任何Linux命令可以使所有运行php scrip的进程都处于等待模式?

Thanks in advance. 提前致谢。

Probably too late for the person who asked this question, but the session can be unlocked before the script ends using function session_write_close(). 对于问这个问题的人来说可能为时已晚,但是可以在脚本结束之前使用函数session_write_close()解锁会话。 You can do something like this: 您可以执行以下操作:

<?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);
?>

Alternatively, you can re-open the session at the stream end. 或者,您可以在流端重新打开会话。 We use this to limit number of concurrent per-user downloads: 我们使用它来限制每用户并发下载的数量:

<?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"]--;
?>

Couldn't find any PHP option 'session lock timeout' 找不到任何PHP选项“会话锁定超时”

To list the session files accessed, try lsof |grep session 要列出访问的会话文件,请尝试lsof |grep session

You should get a output like that 你应该得到这样的输出 在此处输入图片说明

The line with the 16uW is the PHP process that locks the actual session files 16uW的行是锁定实际会话文件的PHP进程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM