简体   繁体   中英

Handle lots of session files with apache2 and php

I'm currently running into a huge problem regarding performance more precisely: Load generated through lots of I/O on an flat sessions folder with lots of files (+100.000).

The sessionfiles/htdocs folder is located on an managed storage - two seperate servers (behind a loadbalancer) are using these files (apache2) through an nsf-mount and are accessing the same sessions folder (to keep it persistent) at once.

Unfortunately the project is highly frequented and is generating a lot of sessionfiles. Even with ans max_lifetime of 2 hours we're generating +100.000 sessionfiles which is way to much for IO Nodes.

Is there a possibility to split - dynamically - these sessions into subfolders? eg all sessionfiles with sess_1* into /tmp/sessions/1, sess_2 into /tmp/sessions/2 and so on? With this approach the storage/IO Nodes only had to handle ~10.000 each folder which should speed up the garbage collection and should guard against IO Load.

I found this excerpt from the PHP (session.save_path) doc:

http://de3.php.net/manual/en/session.configuration.php#ini.session.save-path

There is an optional N argument to this directive that determines the number of directory levels your session files will be spread around in. For example, setting to '5;/tmp' may end up creating a session file and location like /tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If . In order to use N you must create all of these directories before use. A small shell script exists in ext/session to do this, it's called mod_files.sh, with a Windows version called mod_files.bat. Also note that if N is used and greater than 0 then automatic garbage collection will not be performed, see a copy of php.ini for further information. Also, if you use N, be sure to surround session.save_path in "quotes" because the separator (;) is also used for comments in php.ini.

Does anyone have been implementing this before in php and could provide me with some sample php code to handle sessionfiles in subfolders using this mod_files.sh?

unfortunatly its pretty poorly documented ...

Sometimes the solution is easier than it might appear at first. Somehow I thought the PHP has to handle and manage the apache requests to the sessions directory tree. However the Apache does it on its own once the session:save_path has been changed.

1.) call this (modified) script ( http://snipplr.com/view/27710/modfilessh-php/ ) once via ssh:

*sh path/to/script/mod_files.sh path/to/sessions depth* (in my case: "mod_files.sh /tmp/sessions 1"

2.) doublecheck chown rights of new sessions directory tree

3.) change "session.save_path" to "1;/tmp/sessions"

Thanks for your help nevertheless!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM