开发者

Problem with function session_start() (works slowly)

开发者 https://www.devze.com 2022-12-14 00:03 出处:网络
I have a problem wtih session_start() on primary server. When I load page for the first time, it takes less than 1 second to complete request. If I\'ll wait for approximately 12-15 seconds and then re

I have a problem wtih session_start() on primary server. When I load page for the first time, it takes less than 1 second to complete request. If I'll wait for approximately 12-15 seconds and then reload page, time of loading will be the same. But when I'm trying to refresh page after, for example, 3 or 5 seconds after initial loading, time of the server's response equals 10 seconds.

I made some tests to define a bottleneck in my script and I found out, that function session_start() execut开发者_如何学Ces for 9.8 seconds. I'm using PEAR package HTTP_Session2. Here is code snippet:

HTTP_Session2::useCookies(SESSION_USE_COOKIE);
/* Next line was added to make logging of execution time possible. */
self::writeToFile('HTTP_useCookies(1) -> '.self::getWorkTime()); 
HTTP_Session2::start("SID");
self::writeToFile('HTTP_start(2) -> '.self::getWorkTime());
HTTP_Session2::setExpire(time() + SESSION_EXPIRE);
self::writeToFile('HTTP_setExpire(3) -> '.self::getWorkTime());

Text of the logs:

//First loading (13:34:35)
HTTP_useCookies(1) -> 0.00038
HTTP_start(2) -> 0.00077
HTTP_setExpire(3) -> 0.00090

// Second loading (13:34:39)(4 seconds later)
HTTP_useCookies(1) -> 0.00029
HTTP_start(2) -> <<<<<< 10.80752 >>>>>
HTTP_setExpire(3) -> <<<<<< 10.80780 >>>>>

//Third loading (13:34:56)
HTTP_useCookies(1) -> 0.00041
HTTP_start(2) -> 0.00071
HTTP_setExpire(3) -> 0.00083

So I found, that problem is in the HTTP_Session2::start() function. Code of the function HTTP_Session2::start():

public function start($name = 'SessionID', $id = null)
{
  self::name($name);
  if (is_null(self::detectID())) {
    if ($id) {
      self::id($id);
    } else {
      self::id(uniqid(dechex(rand())));
    }
  }
  session_start();
  if (!isset($_SESSION['__HTTP_Session2_Info'])) {
    $_SESSION['__HTTP_Session2_Info'] = self::STARTED;
  } else {
    $_SESSION['__HTTP_Session2_Info'] = self::CONTINUED;
  }
}

I can't understand what is the cause of time delay. Probably, there are wrong Apache settings on the server. Or, maybe, there are some 'locks' on files with session information.

Maybe, someone has already encountered such problems and can help to solve it.


The file containing the session's informations is locked during the time PHP serves a request.

So, if you have one PHP script (using a session) that's currently being executed, and the same user sends another request, the second request will wait until the first is finished.

0

精彩评论

暂无评论...
验证码 换一张
取 消