doupao1978 2013-10-04 09:17
浏览 45

Apache2和PHP会话 - 它会导致随机减速吗?

I have a application consisting of HTML (AngularJS) client and PHP backend. All communication between client and server is done using XMLHTTPRequests (of course except of loading first HTML file and static resources - JS/CSS...). Server exposes some API endpoints and client makes request to these URL. Once server receives request, it checks $_SESSION to check if user is logged in.

My question is, is it possible that reading (not writing to) from $_SESSION upon almost each request could cause major hangs in responses? For instance, the application works for several requests and then random request is sent and response is received after minutes (15 is record so far). It also seems that the request is processed that late (according to dummy error_log test), so the slowdown is not caused by operations in PHP my code.

Maybe it is a stupid question, but I've already doubled apache's ServerLimit (1000) but no luck. I also have another PHP application on this server which works fine, the only difference I could think of is the working application is barely checking $_SESSION in combination of XMLHTTPRequests.

PHP version: 5.3.3

  • 写回答

1条回答 默认 最新

  • dongtiao0657 2013-10-04 09:56
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿