diff options
| author | Ondřej Surý <ondrej@sury.org> | 2014-08-19 09:54:04 +0200 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2014-08-19 09:54:04 +0200 |
| commit | d91c47ef76624788bfb1b9f1127e5aa82d13df10 (patch) | |
| tree | a8da0ea0dff404fca8f7faba033706f9ac1e086a /debian/sessionclean | |
| parent | b65bd492c7c0ada194d89a355ba6f4c9f2298c4e (diff) | |
| download | php-d91c47ef76624788bfb1b9f1127e5aa82d13df10.tar.gz | |
More fixes and improvements to session cleaning script
Diffstat (limited to 'debian/sessionclean')
| -rw-r--r-- | debian/sessionclean | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/debian/sessionclean b/debian/sessionclean index 8d77ff1fe..d99c27048 100644 --- a/debian/sessionclean +++ b/debian/sessionclean @@ -1,22 +1,22 @@ #!/bin/sh -e -SAPIS="apache2:apache2 apache2filter:apache2 cgi:php5 fpm:php5-fpm" +SAPIS="apache2:apache2\napache2filter:apache2\ncgi:php5\nfpm:php5-fpm" # Iterate through all web SAPIs ( -PROC_NAMES="" -for sapi in $SAPIS; do - conf_dir=$(echo "$sapi" | cut -d: -f1) - proc_name=$(echo "$sapi" | cut -d: -f2) - +proc_names="" +echo -e "$SAPIS" | \ +while IFS=: read -r conf_dir proc_name; do if [ -e /etc/php5/${conf_dir}/php.ini ]; then - save_handler=$(php5 -c /etc/php5/${conf_dir}/php.ini -d "error_reporting='~E_ALL'" -r 'print ini_get("session.save_handler");' | sed -e 's/.*;//') - save_path=$(php5 -c /etc/php5/${conf_dir}/php.ini -d "error_reporting='~E_ALL'" -r 'print ini_get("session.save_path");' | sed -e 's/.*;//') - gc_maxlifetime=$(php5 -c /etc/php5/${conf_dir}/php.ini -d "error_reporting='~E_ALL'" -r 'print ini_get("session.gc_maxlifetime")/60;') + # Get all session variables once so we don't need to start PHP to get each config option + session_config=$(php5 -c /etc/php5/${conf_dir}/php.ini -d "error_reporting='~E_ALL'" -r 'foreach(ini_get_all("session") as $k => $v) echo "$k=".$v["local_value"]."\n";') + save_handler=$(echo "$session_config" | sed -ne 's/^session\.save_handler=\(.*\)$/\1/p') + save_path=$(echo "$session_config" | sed -ne 's/^session\.save_path=\(.*\)$/\1/p') + gc_maxlifetime=$(($(echo "$session_config" | sed -ne 's/^session\.gc_maxlifetime=\(.*\)$/\1/p')/60)) if [ "$save_handler" = "files" -a -d "$save_path" ]; then proc_names="$proc_names $proc_name"; - printf "%s:%s:%s\n" "$save_path" "$gc_maxlifetime" + printf "%s:%s\n" "$save_path" "$gc_maxlifetime" fi fi done @@ -24,7 +24,7 @@ done for pid in $(pidof $proc_names); do find "/proc/$pid/fd" -ignore_readdir_race -lname "$save_path/sess_\*" -exec touch -c {} \; done -) | sort -r | sort -u -t: -k 1,1 | while IFS=: read -r save_path gc_maxlifetime; do +) | sort -rn -t: -k2,2 | sort -u -t: -k 1,1 | while IFS=: read -r save_path gc_maxlifetime; do # find all files older then maxlifetime and delete them find -O3 "$save_path" -depth -mindepth 1 -name 'sess_*' -ignore_readdir_race -type f -cmin "+$gc_maxlifetime" -delete done |
