What do you think about running this for each SAPI?  It's actually *way*
more efficient:

for pid in $(pidof "$sapi"); do
        find "/proc/$pid/fd" -lname "$session_save_path/*" -exec touch {} \;
done

That will iterate all the PIDs of the running SAPI (we'll need to
iterate them as well), then find all the files it has open and touch
them.

This is more efficient than lsof since it looks only at the files open
by the SAPI in question, instead of every process.  As an example,
here's the timing of my proposed way and the current way:

kamermans@steve-ubuntu:~$ time for pid in $(pidof apache2); do sudo find 
"/proc/$pid/fd" -lname "/var/lib/php5/*" -print -exec touch {} \; ; done
/proc/4202/fd/21

real    0m0.143s
user    0m0.069s
sys     0m0.077s

kamermans@steve-ubuntu:~$ time sudo /usr/bin/lsof -w -l +d /var/lib/php5
COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
apache2 4202       33   21uW  REG    8,3        0 277620 
/var/lib/php5/sess_bbn8sh6ljim484c4qt3inubhr3

real    0m1.079s
user    0m0.514s
sys     0m0.845s


Notice that my version returns /proc/4202/fd/21, but that is the file 
descriptor which is a symbolic link to 
/var/lib/php5/sess_bbn8sh6ljim484c4qt3inubhr3.  Touching the link touches the 
file, so the effect is the same.  Also, since the find command finds and 
touches the file in (almost) one operation, so it's unlikely the file will 
disappear between the time that it's found and the time that it's touched.

Yet another option is to alter the lsof call to restrict it to just
processes that match the given name(s).  This is also fast, although it
not quite as fast as the aforementioned /proc method in my test:

kamermans@steve-ubuntu:~$ time sudo /usr/bin/lsof -w -l -a +d /var/lib/php5 -c 
apache2
COMMAND  PID     USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
apache2 4202       33   21uW  REG    8,3        0 266585 
/var/lib/php5/sess_18and1t1ej6frr9kjai3m1dbj4

real    0m0.182s
user    0m0.074s
sys     0m0.091s

Note that I added "-a" to AND the directory and command constraint,
otherwise they would be OR'd.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1356113

Title:
  PHP5 session clean cron job causes OOM

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1356113/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to