与函数在session_start(问题)(慢腾腾) [英] Problem with function session_start() (works slowly)

查看:76
本文介绍了与函数在session_start(问题)(慢腾腾)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有wtih 问题在session_start()在主服务器上。当我加载页面的第一次,它需要不到1秒即可完成申请。如果我要等待大约12-15秒,然后刷新页面,加载时间将是相同的。但是,当我尝试之后刷新页面,例如,经过3秒或5秒初始加载,服务器的响应时间等于10秒。

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.

我做了一些测试,在我的脚本,定义一个瓶颈,我发现,该功能在session_start()执行9.8秒。我使用PEAR包HTTP_Session2。 这里是code片断:

I made some tests to define a bottleneck in my script and I found out, that function session_start() executes 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());

日志的文字:

//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

于是我发现,问题出在 HTTP_Session2 ::开始()功能。该函数的code HTTP_Session2 ::开始()

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;
  }
}

我不明白是什么时间延迟的原因。也许,有服务器上的错误的Apache设置。或者,也许,有与会话信息文件的一些'锁'。

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.

推荐答案

包含会话的信息文件中PHP提供请求的时间被锁定。

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

所以,如果你有一个PHP脚本,因此目前正在执行,和相同的用户发送另一个请求(使用会话),第二个请求将等到第一个完成。

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.

这篇关于与函数在session_start(问题)(慢腾腾)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆