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

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能