0

我有一个由 HTML (AngularJS) 客户端和 PHP 后端组成的应用程序。客户端和服务器之间的所有通信都是使用 XMLHTTPRequests 完成的(当然除了加载第一个 HTML 文件和静态资源 - JS/CSS ...)。服务器公开一些 API 端点,客户端向这些 URL 发出请求。一旦服务器收到请求,它会检查 $_SESSION 以检查用户是否已登录。

我的问题是,是否有可能在几乎每个请求时从 $_SESSION 读取(而不是写入)可能会导致响应严重挂起?例如,应用程序处理多个请求,然后发送随机请求并在几分钟后收到响应(到目前为止记录了 15 个)。似乎请求处理得太晚了(根据 dummy error_log 测试),所以减速不是由 PHP 我的代码中的操作引起的。

也许这是一个愚蠢的问题,但我已经将 apache 的 ServerLimit (1000) 翻了一番,但没有运气。我在这台服务器上还有另一个 PHP 应用程序工作正常,我能想到的唯一区别是工作应用程序几乎没有检查 $_SESSION 与 XMLHTTPRequests 的组合。

PHP版本:5.3.3

4

1 回答 1

1

I could not find a specific reason for your problem but there if you are using php 5.1.x it loads all session data in to memory at session_start() . As a result of this file access in the entire server will be delayed .

If your server php version is not 5.1 and if it is latest 5.4 or .5 then , the possible problem would come due to creation of large number of session temp files .

This some times causes problems with filesystem limits in operating system . so you need to set the session time out to less period .

Also while reading there will be much load on the operating system .

This can be achieved by using config parameter session.gc_maxlifetime

PHP runs garbage collection on expired sessions after the current session is loaded and by using session.gc_probability and session.gc_divisor it calculates the probability that garbage collection will run.

So set session maxlife time to max 1 and see the performance .

Because of this reason most of the web applications provide an option called remember me.

And those applications usually replaces session_start and enforces a timeout if user is idle for a particular span of time .

Hope this helps

References : -

Session time out best practices

Session Clustering White paper

于 2013-10-04T09:56:42.123 回答