Results 1 to 2 of 2
Hello, I have server on which is Plesk last version, CentOS 6.5 64 bit and PHP 5.3.3 installed. I have big problem with php sessions stored at var/lib/php/session . Every ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-10-2014 #1
- Join Date
- Apr 2008
Problem with folder var/lib/php/session size more than 4Gb
I have server on which is Plesk last version, CentOS 6.5 64 bit and PHP 5.3.3 installed. I have big problem with php sessions stored at var/lib/php/session . Every created session stay in this folder and don't auto delete after expire.
Can you help me and tell me how to make some script or code to auto delete expired session files?
And how that file to add into cron to execute example every day at some time.
Thank you very much
- 02-12-2014 #2
- Join Date
- May 2011
i'm not sure how to determine whether your session files have expired - there is hopefully a way to do that w/in the configuration of PHP itself.
for the sake of the argument, let's say that files that haven't been modified in 24 hours are considered expired. then you could run this command to delete those files:
find /var/lib/php/session/ -name $FILE_NAME_REGEX -type f -mmin +1440 -delete
so once you have a find/delete command with which you are happy, create a script containing it. for example, su to root and create a file in /root called "del-expired-php-files.sh". in it put:
#!/bin/bash # command(s) to delete expired files find /var/lib/php/session/ -name $FILE_NAME_REGEX -type f -mmin +1440 -delete
now call that script in a cronjob that will run at an interval of your choosing. to do that, still as root, do:
# run command every nite at 10pm to clean up files 0 22 * * * root /root/del-expired-php-files.sh > /tmp/del-files.log 2>&1
note: to trouble-shoot the cron stuff, use this string for the time (instead of 0 22 * * *), to run it every minute:
* * * * * root ...
0 22 * * * /root/del-expired-php-files.sh > /tmp/del-files.log 2>&1