Page 2 of 2

Re: does restarting apache reset php sessions?

Posted: Thu Feb 26, 2009 7:13 pm
by kiwijones
what does it mean if I have no /var/spool/cron/crontabs folder?

Re: does restarting apache reset php sessions?

Posted: Fri Feb 27, 2009 2:29 am
by Weirdan
kiwijones wrote:what does it mean if I have no /var/spool/cron/crontabs folder?
Either your users don't have their individual crontabs, or those crontabs are located somewhere else on your system (but likely somewhere around /var/spool).
VladSun wrote:
...cron also reads /etc/crontab, which is in a slightly different format
(see crontab(5)). Additionally, cron reads the files in /etc/cron.d:
it treats the files in /etc/cron.d as in the same way as the
/etc/crontab file
Yeah, those have to be scanned as well.

Re: does restarting apache reset php sessions?

Posted: Fri Feb 27, 2009 7:57 am
by inghamn
Sessions are independent of Apache, even when you are running PHP inside of Apache. I restart Apache all the time without disrupting PHP sessions.

Sessions are stored and garbage collected by PHP. If you're using file-based, the files are stored on the hard drive. Restarting Apache does not clear out the session files.

Unless you're doing some special, cron also has nothing to do with it. PHP is responsible for deleting session files. That's what the gc_ parameters in php.ini control. So, every time you call session_start(), PHP looks for session files on the hard drive (again, this is with file-based storage). Once it finds files, it does a quick scan to see if any session files need to be garbage collected. Then, if the user has sent a SESSID in the request, PHP tries to load the requested session.

I may have the order of operations off a little there, actually. But the point is, sessions will survive even with Apache shut off. (As long as you don't rm them yourself.)

Re: does restarting apache reset php sessions?

Posted: Fri Feb 27, 2009 9:11 am
by VladSun
inghamn wrote:Unless you're doing some special, cron also has nothing to do with it.
Well, in fact every PHP installation (on Linux) modifies crontabs. So, while I agree that most of the clean up is done by the GC, there is still some cron jobs involved.
inghamn wrote:PHP is responsible for deleting session files. That's what the gc_ parameters in php.ini control. So, every time you call session_start(), PHP looks for session files on the hard drive (again, this is with file-based storage).
Not exactly - GC will not clean the old sessions on *every* session_start - that depends on session.gc_probability and session.gc_divisor:

Code: Select all

session.gc_probability = 1
session.gc_divisor = 100
so it means there is 1/100 probability that it will check for expired sessions and remove them.

In fact, playing with session.gc_maxlifetime is a PITA when multiple web applications run on a single server, because the GC can not tell which file belongs to a session with shorter/longer lifetime.

Re: does restarting apache reset php sessions?

Posted: Fri Feb 27, 2009 9:46 am
by inghamn
VladSun wrote:Well, in fact every PHP installation (on Linux) modifies crontabs. So, while I agree that most of the clean up is done by the GC, there is still some cron jobs involved.
I double checked my installations, and cannot find any PHP stuff in any of my crons. Am I missing something here? I did not think PHP added anything to cron.
VladSun wrote:In fact, playing with session.gc_maxlifetime is a PITA when multiple web applications run on a single server, because the GC can not tell which file belongs to a session with shorter/longer lifetime.
Too true. I was having some troubles with this recently. Now I currently sandbox each application's session files in the bootstrap

Code: Select all

 
    ini_set('session.save_path',APPLICATION_HOME.'/data/sessions');
    ini_set('session.gc_maxlifetime',30*60);
    session_start();
 

Re: does restarting apache reset php sessions?

Posted: Fri Feb 27, 2009 10:57 am
by VladSun
inghamn wrote:
VladSun wrote:Well, in fact every PHP installation (on Linux) modifies crontabs. So, while I agree that most of the clean up is done by the GC, there is still some cron jobs involved.
I double checked my installations, and cannot find any PHP stuff in any of my crons. Am I missing something here? I did not think PHP added anything to cron.
debian:~# cat /etc/cron.d/php5
# /etc/cron.d/php5: crontab fragment for php5
# This purges session files older than X, where X is defined in seconds
# as the largest value of session.gc_maxlifetime from all your php.ini
# files, or 24 minutes if not defined. See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -r -0 rm
cat /etc/cron.d/php4
# /etc/cron.d/php4: crontab fragment for php4
# This purges session files older than X, where X is defined in seconds
# as the largest value of session.gc_maxlifetime from all your php.ini
# files, or 24 minutes if not defined. See /usr/lib/php4/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 * * * * root [ -d /var/lib/php4 ] && find /var/lib/php4/ -type f -cmin +$(/usr/lib/php4/maxlifetime) -print0 | xargs -r -0 rm
Two different Debian servers.
I think crond is used for session files cleanup because it's not guaranteed that PHP interpreter will be executed in a given time period - so, GC could not be called.

Re: does restarting apache reset php sessions?

Posted: Fri Feb 27, 2009 11:31 am
by inghamn
Ahh now I understand. Those aren't from PHP, those cron files are installed as part of your distribution. Those are very distribution specific. On all my servers, I compile Apache, MySQL, and PHP from source. Installing PHP from source does not install any cron.

Re: does restarting apache reset php sessions?

Posted: Fri Feb 27, 2009 5:47 pm
by kiwijones
this discussion is fast overwhelming my mental faculties ... i should read up on this sh*t :)

but thanks all the same you guys ... if it wasn't for you, i would never know that deletion of sessions involved probability! :)

Re: does restarting apache reset php sessions?

Posted: Sat Feb 28, 2009 10:07 pm
by josh
on centos, fedora and redhat and possibly others you can do crontab -e to edit the crontab for the current user in the default text editor

Re: does restarting apache reset php sessions?

Posted: Sun Mar 08, 2009 10:55 am
by kaisellgren
Restarting Apache will not clear sessions.

Switching from HTTPD to another will not do it either.

Even changing from Windows to Linux will not do that, if you do the switch properly or the session data is not on that machine.