Wednesday, August 1, 2012

Re: Database sessions garbage collection issue

The function is located here:
http://api13.cakephp.org/view_source/cake-session/#l-784 

The value passed is the one from the php config,  session.gc_maxlifetime, so in my case 3600.


On Wednesday, August 1, 2012 7:58:09 PM UTC+2, cricket wrote:
Where is __gc() called and what value is passed to it?

On Wed, Aug 1, 2012 at 3:12 AM, Crazy wrote:
> I'm having some issues with my sessions.
>
> It's probably configuration somewhere, but don't know what to change/where
> to look.
>
> I'm using database sessions for my cake application, these sessions are not
> getting cleaned up.
>
> The app in question I have the issue on is an old one written on 1.3.10
> running with php version 5.3.5. The garbage collection function in the 2.x
> branch is the same so don't think the framework version will matter.
>
> I've tracked down the issue to the function __gc located in the CakeSession
> class and that function is registered there in the php
> session_set_save_handler function, this is the function in question:
>
> /**
>  * Helper function called on gc for database sessions.
>  *
>  * @param integer $expires Timestamp (defaults to current time)
>  * @return boolean Success
>  * @access private
>  */
> function __gc($expires = null) {
>     $model =& ClassRegistry::getObject('Session');
>
>     if (!$expires) {
>         $expires = time();
>     }
>
>     $return = $model->deleteAll(array($model->alias . ".expires <" =>
> $expires), false, false);
>     return $return;
> }
>
> Now, the comments say that $expires is a timestamp, but this isn't correct
> according to the php docs:
>
> gc($lifetime)
> The garbage collector callback is invoked internally by PHP periodically in
> order to purge old session data. The frequency is controlled by
> session.gc_probability and session.gc_divisor. The value of lifetime which
> is passed to this callback can be set in session.gc_maxlifetime. Return
> value should be TRUE for success, FALSE for failure.
>
> The value for $lifeime, so gc_maxlifetime in php.ini is the following:
>
> ; After this number of seconds, stored data will be seen as 'garbage' and
> ; cleaned up by the garbage collection process.
> session.gc_maxlifetime = 3600
>
> So this results in a query that never deletes anything:
>
> delete from cake_sessions where expires < 3600;
>
> Could someone clarify what I'm doing wrong or if this is an issue in cake
> itself?
>
>
> I've posted this on ask.cakephp.org as well, when I find the answer I'll
> make sure to update both locations.
>
> http://ask.cakephp.org/questions/view/database_sessions_garbage_collection_issue
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: