简体   繁体   中英

session has already been started by session.auto-start or session_start() in Zend project

I'm writing in php using Zend Framework version 1.11.11. Sometimes I receive error

session has already been started by session.auto-start or session_start()

After page refreshing this error disappears. I read several posts about this problem. I checked configs and session.auto_start is set to Off. I don't call session_start() directly, for working with session I use only Zend_Session component.

What can be the cause of this problem? Can it be connected with garbage collector?

This seems to be related to a session cleanup task that Zend tries to perform. By default apache only has write access to the session directory (on an Ubuntu box it would be /var/lib/php5). This causes the cleanup to fail, resulting in intermittent HTTP/500 errors.

Easiest is to give read access to apache by doing either of 1) chmod a+r /var/lib/php5 2) chgrp www-data /var/lib/php5; chmod g+r /var/lib/php5

The above commands assume you're running Ubuntu. In other distros, adjust the username/path.

I'm guessing this is on a debian server? If not, this may not be the solution... but we ran into this on our Ubuntu based installations.

This is happening because of the combination of the installed PHP package and the cron scripts that are running to take care of the session cleanup. (for whatever reason... not sure why they're doing that...)

We were successful by doing the following things: - removing the cron job to clear out the PHP session stuff (trust me, its there - its annoying) - chmod www-data:www-data /var/lib/php5 (or equivalent info) - session.gc_probability = 1 in your php.ini file

May not be the best solution, but it took care of it for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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