-
Notifications
You must be signed in to change notification settings - Fork 803
"session has already been started by session.auto-start or session_start()" error message is misleading #25
Comments
This issue was ported from the ZF2 Jira Issue Tracker at Known GitHub users mentioned in the original message or comment: |
I was the original filer of this bug, back when it was on Jira. |
Still have this problem.. @vestigal Did you solved it? if yes, how? Thanks! |
I just experienced this bug now. In my case it was caused by the fact that sessions directory was not writable. It seems that Zend_Session checks only for success and assumes that any other result means session is already started. cc @simonrjones |
I actually debugged it to the fact that the exception is not thrown but added as a response exception instead - it's because it's initialized before is added to exception stack, but later in the request when actually using the session the new "session already started" it's after the error handler set to throw the exceptions - so that one is thrown, but the first one is forgotten. But it's still in the exceptions stack ( One way to fix this could be to throw the first exception from exception stack if one is present. But that may not be the right one. |
What would you think would be a good way to fix this? I could do a PR to fix it, but I'm not sure how exactly to fix it. |
Currently facing this issue on my server - no changes made by us - also the folder are accessible and writeable. |
You need to debug it to find out the core exception as described in my post above. That will set you on the right path :) |
I found the issue. It was a long running - and sadly not good configured project. After thinking about permission problems or similar it was a simply as you can think. There where too many open session or better too many OLD session and the IIS simply couldn't handle that much files so the PHP IO was higher than the PHP execution time - removing the old Session's the problem simply was gone. Thanks anyway @tomasfejfar! |
This error message can also be caused by wrong permissions on the sessions folder, if the folder is not writeable or doesn't belong to the right user. |
Jira Information
Description
On Ubuntu, garbage collection for sessions is taken care of by a cron job, rather than within PHP. If one downloads the PHP packages from Ubuntu's repository, then session.gc_probability in php.ini is set to 0, so PHP never runs the garbage collection for sessions. Unfortunately, if one changes session.gc_probability to something else, then one randomly encounters errors when the session garbage collection is run.
The error is something like this:
The issue appears to be that garbage collection is failing, and this causes Zend Framework to think that a session has already been started. The easiest way to test this that I've found is to set session.gc_probability to 1 and session.gc_divisor to 1, so that the error is triggered every time one tries to start a session. With the default values, the error usually only shows up once every hundred times the page loads. Of course, you'll need to be testing this on Ubuntu with one of their PHP packages to see this error.
It would be nice if errors could not be thrown in this case, or if the error message could be more descriptive. It took awhile to track down the cause of this error, but I eventually found the answer on [Stack Overflow|http://stackoverflow.com/a/7979354/862204].
The text was updated successfully, but these errors were encountered: