標籤:
打算開啟php的session功能,並將session資訊存到檔案裡。
修改php.ini,開啟session功能:
#將session資訊存到檔案中
session.save_handler = files
#開啟二級目錄存放session檔案。如果不指定,會直接在/home/www/php-session/目錄下存session檔案,當session檔案較多時,不方便查看檔案,建議啟用多級目錄。
session.save_path = "2;/home/www/php-session/"
#啟用cookies
session.use_cookies = 1
重啟php-fpm服務。
發現,/home/www/php-session目錄下還是沒有session檔案產生。
糾結了許久,才發現,php不會自動產生session的目錄結構,因此session資訊無法寫進。需要藉助源碼包 ext/session 目錄下的 mod_files.sh 指令碼來組建目錄結構。
# sh ext/session/mod_files.sh /home/www/php-session 2Usage: ext/session/mod_files.sh BASE_DIRECTORY DEPTH HASH_BITSBASE_DIRECTORY will be created if it doesn‘t existDEPTH must be an integer number >0HASH_BITS(session.hash_bits_per_charactor) should be one of 4, 5, or 6
根據報錯資訊,可知還缺少一個參數要指定。
查看php.ini檔案:
; Define how many bits are stored in each character when converting; the binary hash data to something readable.; Possible values:; 4 (4 bits: 0-9, a-f); 5 (5 bits: 0-9, a-v); 6 (6 bits: 0-9, a-z, A-Z, "-", ","); Default Value: 4; Development Value: 5; Production Value: 5; http://php.net/session.hash-bits-per-character; session.hash_bits_per_character = 5
在生產環境下,php官方推薦將 session.hash_bits_per_character 設定為5 。
去掉注釋,修改為:session.hash_bits_per_character = 5
重啟php-fpm服務。
重建session目錄結構:
# sh ext/session/mod_files.sh /home/www/php-session 2 5
session目錄下,正常產生session檔案了。
php session目錄無法寫進資料的問題