目錄
gc (garbage collection)
- session.gc_maxlifetime
- session.gc_probability
- session.gc_divisor
- session.cookie_lifetime
- session.use_strict_mode
session.serialize_handler
Session Save Location
check session setting
php -i | grep session
gc (garbage collection)
# number of seconds after which data will be seen as 'garbage' and potentially cleaned up.
* 每次 access 它(session)時都會 update ctime 但不會影響內容.
session.gc_maxlifetime "1440"
* max value for "session.gc_maxlifetime" is 65535. values bigger than this may cause php session stops working.
# session.gc_divisor coupled with session.gc_probability
# defines the probability that the process is started on every session initialization.
session.gc_probability "1"
session.gc_divisor "100"
gc_probability/gc_divisor
e.g. 1/100
means there is a 1% chance that the GC process starts on each request(session initialization).
# specifies the lifetime of the cookie in seconds which is sent to the browser.
# The value 0 means "until the browser is closed." Defaults to 0.
Note:
If different scripts have different values of session.gc_maxlifetime
but share the same place for storing the session data then the script with the minimum value will be cleaning the data.
In this case, use this directive together with session.save_path.
session.cookie_lifetime
# Browner 會在指定時間後刪除 session cookie
# 當 cookie 被刪除後, 相當於 logout
session.cookie_lifetime "0"
session.use_strict_mode
# does not accept uninitialized session ID
# If uninitialized session ID is sent from browser, new session ID is sent to browser.
# Defaults to 0
session.use_strict_mode "0"
Debian 上的 php session
在 Debian 上, Default: "session.gc_probability = 0"
它的 session expire 係由 /etc/cron.d/php5 處理
09,39 * * * * root [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete
由於 drupal 的 session handler 是
ini_set('session.save_handler', 'user');
所以要人手加回
ini_set('session.gc_probability', 1); ini_set('session.gc_divisor', 100);
session.serialize_handler
Defaults to "php"
defines the name of the handler which is used to serialize/deserialize data.
Older serialize handlers:
- PHP internal formats (name php and php_binary)
* cannot store numeric index nor string index contains special characters (| and !) in $_SESSION.
在 5.5.4 上額外有:
- PHP serialize format (name php_serialize) <- plain serialize/unserialize ()
# 當 session 放在 memcache 時, 用 php_serialize 會好一些, 因為這樣其他 program 可以拿來用
session.serialize_handler = php_serialize
Session Save Location
# Defaults "files" session.save_handler = files session.save_path = /var/lib/php/session
Filename: sess_???
registered handlers can be obtained
1. per-installation basis <-- ("files")
2. session_set_save_handler() <-- Sets user-level session storage functions ("user")
P.S.
You can't use the session autostart feature with "user" set in your php.ini.
Use instead the auto_prepend_file directive in the php.ini and
point it to your save_handler with an session_start() at the end.
Per vhosts Setting
php_admin_value session.save_path /var/www/clients/client3/web2/tmp
chmod 777 /var/www/clients/client3/web2/tmp
DOC
http://php.net/manual/en/session.configuration.php