为什么在设置$ _SESSION值时会看到执行超时? [英] Why would I be seeing execution timeouts when setting $_SESSION values?

查看:98
本文介绍了为什么在设置$ _SESSION值时会看到执行超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP错误日志中看到以下错误:

I'm seeing the following errors in my PHP error logs:

PHP致命错误:D中超过60秒的最大执行时间:第3行的\sites \s105504 \过\ index.php

PHP致命错误:超过60秒的最长执行时间第4行的D:\\\ites \s105504 \ #\\\ search.php

有问题的行是:

index.php:

01 <?php
02 session_start();
03 ob_start();
04 error_reporting(E_All);
05 $_SESSION['nav'] = "range";  // <-- Error generated here

search.php

01 <?php
02 
03 session_start();
04 $_SESSION['nav'] = "range";
05 $_SESSION['navselected'] = 21; // <-- Error generated here

分配真的需要60多秒a $ _ SESSION [] 价值?

Would it really take as long as 60+ seconds to assign a $_SESSION[] value?

平台是:


  • Windows 2003 SP2 + IIS6

  • Windows 2003的FastCGI(原始RTM版本)

  • PHP 5.2。 6非线程安全构建

会话过期时,会话数据文件在服务器上清除时没有任何问题。我看到的最旧的 sess_XXXXXXXXXXXXXX 文件大约是2个小时。

There aren't any issues with session data files being cleared up on the server as sessions expire. The oldest sess_XXXXXXXXXXXXXX file I'm seeing is around 2 hours old.

没有明显的磁盘超时事件日志或其他此类磁盘运行状况问题可能表示创建会话数据文件有困难。

There are no disk timeouts evident in the event logs or other such disk health issues that might suggest difficulty creating session data files.

该站点也位于服务器上,负载不高。该网站很忙,但没有受到重创,而且非常敏感。只是我们每三到四个小时就会连续三到四次出现这些错误。

The site is also on a server that isn't under heavy load. The site is busy but not being hammered and is very responsive. It's just that we get these errors, three or four in a row, every three or four hours.

我还应该补充一点,我不是这个错误的原始开发者代码,它属于开发人员早已离职的客户。

I should also add that I'm not the original developer of this code and that it belongs to a customer who's developer has long since departed.

推荐答案

会话阻塞。 session_start()将阻止执行,直到它可以获得该特定会话文件的独占锁定。这是为了防止并发问题的出现。当您在每个脚本中完成会话后,您可以通过发出 session_write_close()来解决此问题。您在下一行看到它的原因是 session_start()块的数量超过最大执行时间。所以当它返回时,下一行在时间限制之后执行,这就是引发错误的地方。

Sessions are blocking. session_start() will block execution until it can get an exclusive lock on that particular session's file. This is to prevent concurrency issues from cropping up. You can solve it by issuing a session_write_close() when you're done with the session in each script. The reason you're seeing it on the next line, is session_start() blocks for > than the max execution time. So when it returns, the next line is executed after the time limit, so that's where the error is raised.

参见: session_write_close()了解更多信息

哦,并根据您发布的错误,错误在 ob_start(); $ _ SESSION ['nav'] =范围生成; 分别为行,而不是您在代码部分中指定的第5行......

Oh, and based on the errors you posted, the error is generated at the ob_start(); and the $_SESSION['nav'] = "range"; lines respectively, not the line 5 that you indicated in the code section...

这篇关于为什么在设置$ _SESSION值时会看到执行超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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