php session目錄無法寫進資料的問題

來源:互聯網
上載者:User

標籤:

 打算開啟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目錄無法寫進資料的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.