does restarting apache reset php sessions?
Moderator: General Moderators
Re: does restarting apache reset php sessions?
what does it mean if I have no /var/spool/cron/crontabs folder?
Re: does restarting apache reset php sessions?
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).kiwijones wrote:what does it mean if I have no /var/spool/cron/crontabs folder?
Yeah, those have to be scanned as well.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
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: does restarting apache reset php sessions?
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.)
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?
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:Unless you're doing some special, cron also has nothing to do with it.
Not exactly - GC will not clean the old sessions on *every* session_start - that depends on session.gc_probability and session.gc_divisor: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).
Code: Select all
session.gc_probability = 1
session.gc_divisor = 100In 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.
There are 10 types of people in this world, those who understand binary and those who don't
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: does restarting apache reset php sessions?
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: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.
Too true. I was having some troubles with this recently. Now I currently sandbox each application's session files in the bootstrapVladSun 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.
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?
inghamn wrote: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: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.
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
Two different Debian servers.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
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.
There are 10 types of people in this world, those who understand binary and those who don't
- inghamn
- Forum Contributor
- Posts: 174
- Joined: Mon Apr 16, 2007 10:33 am
- Location: Bloomington, IN, USA
Re: does restarting apache reset php sessions?
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?
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!
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?
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
- kaisellgren
- DevNet Resident
- Posts: 1675
- Joined: Sat Jan 07, 2006 5:52 am
- Location: Lahti, Finland.
Re: does restarting apache reset php sessions?
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.
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.