-if [ -n "$RUNTIME4" -a "$RUNTIME5" != "$RUNTIME4" ]; then
- /usr/sbin/tmpwatch ${RUNTIME4} /var/run/php
-fi
+# find minimum gc time from any of the php engines
+find_gc_time() {
+ gc_time=0
+ local gc php
+ for php in php $(cd /usr/bin && ls -1 php[0-9]* 2> /dev/null); do
+ gc=
+ if [ -x /usr/bin/$php ]; then
+ gc=$($php -r 'echo max(round(ini_get("session.gc_maxlifetime")/3600), 1);' 2> /dev/null)
+ elif [ -r /etc/$php/php.ini ]; then
+ gc=$(awk -F"=" '/^session.gc_maxlifetime[ \t]*=/ { t=sprintf("%d", ($2/3600)); if (t<1) { t=1; }; print t; exit;}' /etc/$php/php.ini)
+ fi
+ [ -n "$gc" ] || continue
+
+ if [ "$gc" -lt "$gc_time" ] || [ $gc_time -eq 0 ]; then
+ gc_time=$gc
+ fi
+ done
+}
+
+find_gc_time
+[ $gc_time -gt 0 ] || exit 0
+
+for session_dir in $session_dirs; do
+ cleanup_dir $session_dir
+done
+
+exit 0