session_start 挂起 [英] session_start hangs

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

问题描述

自从几个小时以来,每次您执行 session_start 时,我们的服务器都会挂起.

since a few hours our server hangs every time you do a session_start.

出于测试目的,我创建了一个如下所示的脚本:

For testing purposes i created a script which looks like this:

<?php
session_start();
?>

从控制台调用它挂起,甚至不能用 ctrl-c 停止,只有 kill -9 有效.通过 Apache 调用它也是如此./var/lib/php/session/ 保持为空,但权限绝对没问题,www 可以写入并且对所有父文件夹也有读取权限.

Calling it from the console hangs and it can't even be stopped with ctrl-c, only kill -9 works. The same for calling it via Apache. /var/lib/php/session/ stays empty but permissions are absolutely fine, www can write and also has read permissions for all parent folders.

据管理员称,服务器上没有进行任何更改,也没有为会话注册特殊代码.服务器是 CentOS 4 或 5,昨天一切正常.我们重新启动了服务器并更新了 PHP,但没有任何变化.

According to the admins there were no changes made on the server and there is no special code registered for sessions. The Server is CentOS 4 or 5 and yesterday everything was working perfectly. We rebooted the server and updated PHP, but nothing changed.

我的想法已经用完了,有什么建议吗?

I've ran out of ideas, any suggestions?

更新

我们通过将项目移到另一台服务器解决了这个问题,因此虽然问题仍然存在于一台服务器上,但不再需要立即解决.不过,如果有人对将来遇到类似问题的其他人有想法,我会保持这个问题的开放性.

We solved this problem by moving the project to another server, so while the problem still exists on one server there is no immediate need for a solution anymore. I will keep the question open in case someone has an idea for others having a similar problem in the future, though.

推荐答案

造成这种情况的原因有很多,这里列举几个:

There are many reasons for that, here are a few of them:

A. 会话文件可以以独占方式打开.当文件锁由于某种原因没有正确释放时,它会导致 session_start() 在任何未来的脚本执行中无限挂起.解决方法:使用 session_set_save_handler() 并确保写入函数使用 fopen($file, 'w') 而不是 fopen($file, 'x')

A. The session file could be opened exclusively. When the file lock is not released properly for whatever reason, it is causing session_start() to hang infinitely on any future script executions. Workaround: use session_set_save_handler() and make sure the write function uses fopen($file, 'w') instead of fopen($file, 'x')

B. 切勿在 php.ini 文件中使用以下内容(熵文件为/dev/random"),这会导致您的 session_start() 挂起:

B. Never use the following in your php.ini file (entropie file to "/dev/random"), this will cause your session_start() to hang:

<?php
ini_set("session.entropy_file", "/dev/random");
ini_set("session.entropy_length", "512");
?>

C.session_start() 需要一个目录来写入.

C. session_start() needs a directory to write to.

您可以在普通用户帐户中运行 Apache 和 PHP.当然,Apache 将不得不侦听 80 以外的其他端口(例如 8080).

You can get Apache plus PHP running in a normal user account. Apache will then of course have to listen to an other port than 80 (for instance, 8080).

请务必做到以下几点:- 创建一个临时目录 PREFIX/tmp- 将 php.ini 放入 PREFIX/lib- 编辑 php.ini 并将 session.save_path 设置为您刚刚创建的目录

Be sure to do the following things: - create a temporary directory PREFIX/tmp - put php.ini in PREFIX/lib - edit php.ini and set session.save_path to the directory you just created

否则,您的脚本似乎会在 session_start() 上挂起".

Otherwise, your scripts will seem to 'hang' on session_start().

这篇关于session_start 挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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