简体   繁体   English

PHP 5.3和会话文件夹的问题

[英]Issues with PHP 5.3 and sessions folder

I recently upgraded to PHP 5.3 and since then I get (sporadic) error messages which indicate Apache (or may be the cleaner of the session files) has no permissions to the folder where the sessions are stored. 我最近升级到PHP 5.3,从那时开始,我收到(零星)错误消息,指示Apache(或者可能是会话文件的清理者)对存储会话的文件夹没有权限。
This happens randomly and can't be reproduced with exact steps, which led me to guess it is the session cleaner. 这是随机发生的,无法通过精确的步骤进行复制,这使我猜测它是会话清除程序。
Any one has any experience with such errors? 任何人都有此类错误的经验吗?

The error message (which is fired on the session_start() line) is: 错误消息(在session_start()行上触发)是:

ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied. ps_files_cleanup_dir:opendir(/ var / lib / php5)失败:权限被拒绝。

ls -ltr on the session directory gives: 会话目录上的ls -ltr给出:

drwx-wx-wt  2 root          root          4096 2010-05-25 12:39 php5

Inside this directory I do see session files owned by www-data which is my Apache, and the app does work fine. 在此目录中,我确实看到了www-data拥有的会话文件,这是我的Apache,该应用程序运行正常。 Which makes me wonder, under which user does the session GC runs? 这让我想知道,会话GC在哪个用户下运行?

The fix: In your php.ini set session.gc_probability to 0 解决方法:在您的php.inisession.gc_probability设置为0

The cause I believe I found the answer here http://somethingemporium.com/2007/06/obscure-error-with-php5-on-debian-ubuntu-session-phpini-garbage 我相信我在这里找到了答案的原因 http://somethingemporium.com/2007/06/obscure-error-with-php5-on-debian-ubuntu-session-phpini-garbage

Essentially, the garbage collection is set up to be done by cron jobs on some systems (ie Ubuntu/Debian). 本质上,垃圾收集设置为由某些系统(例如Ubuntu / Debian)上的cron作业完成。 Some php ini executables like php-cli also try to do garbage collection and that results in the error you got. 一些php ini可执行文件(例如php-cli)也尝试进行垃圾回收,这会导致您得到错误。

This seems to be a typical error on Ubuntu servers (I'm using Lucid LTS). 这似乎是Ubuntu服务器上的典型错误(我使用的是Lucid LTS)。 The default permissions of the /var/lib/php5 directory there are / var / lib / php5目录的默认权限为

drwx-wx-wt  2 root     root     4096 2011-11-04 02:09 php5

so it can be written but not read by the web server, I guess that explains the errors. 因此它可以被Web服务器写入但不能被Web服务器读取,我想这可以解释错误。

As Ubuntu has it's own garbage cleaning via cron ( /etc/cron.d/php5 ), it's probably best to disable php's garbage collection as suggested above by Diwant Vaidya. 由于Ubuntu通过cron( /etc/cron.d/php5 )拥有自己的垃圾清理功能,因此最好按照Diwant Vaidya的建议禁用php的垃圾回收功能。

session.gc_probability = 0

There's actually a reason the session folder should not be world readable - as the PHP Manual says: 实际上,有一个原因使得session文件夹不能被世界范围读取-正如PHP手册所述

If you leave this set to a world-readable directory, such as /tmp (the default), other users on the server may be able to hijack sessions by getting the list of files in that directory. 如果将此设置保留在世界可读的目录中,例如/ tmp(默认设置),则服务器上的其他用户可能能够通过获取该目录中的文件列表来劫持会话。

我目前使用的解决方案(我不确定这是正确的解决方案)是将会话文件夹的所有权授予Apache用户(在我的情况下为www-data)。

This issue has been bugging me for a while. 这个问题困扰了我一段时间。 I changed the value as suggested in php.ini and the issue kept occurring. 我按照php.ini中的建议更改了值,此问题不断发生。 I found the same config value in my index.php and also private/Zend/session.php. 我在index.php和private / Zend / session.php中发现了相同的配置值。 So it's worth looking a bit deeper if the issue keeps occurring. 因此,如果问题持续发生,则值得深入研究。 I hope this is useful for someone. 我希望这对某人有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM