Session, in a computer, especially in a network application, is called a "session."
A server traffic is relatively large, because the program needs, the session expiration time is set to 3 hours, resulting in/TMP piled up nearly 200,000 of the session file. This leads to a sharp increase in CPU consumption by the kernel. Because the session read and write involves a lot of small files random read and write, and is concentrated in a directory, iowait also sharply increased.
Consider putting the session into memory first
The simplest way is to mount/tmp as a TMPFS file system, in memory
The second step is to store the session in a directory that is not available.
PHP itself supports multi-level hashing of session
In PHP.ini, the
- Session.save_path =/tmp;
Switch
- "2;/tmp/session"
Indicates that the session is stored in the/tmp/session folder, and is 2 and hashed.
Save exit, wait until the end of the third step to restart PHP
The third step is to create the session storage folder
PHP does not automatically create these folders, but it provides some script for creating folders in the source file. The following script is also useful
- i= "0 1 2 3 4 5 6 7 8 9 a B c d E F"
- for ACM in /span> $I ;
- do
- for x in $I ;
- do
- mkdir -p/tmp/session/ $ACM / $x ;
- done;
- done
- chown -R nobody:nobody/tmp /session
- chmod -R 1777/tmp/session
Because/tmp is used memory, after the server restarts, all the files inside will be lost, so you need to add the above script to/etc/rc.local, and put it before starting PHP
The fourth step, the recycling session
Session after Session.gc_maxlifetime will expire, but will not be deleted immediately after a long time will cause/TMP space occupies a lot. The specific deletion algorithm is lazy to study. The following command can delete the expired session, I define the expiration time is 3 hours.
- find/tmp/session-amin +180- exec RM-RF {};
Put it in cron, execute it in 10 minutes, and do it.
This article has four steps to introduce the hash of the session and the expiration of the collection, I hope it helps you.
http://www.bkjia.com/PHPjc/445794.html www.bkjia.com true http://www.bkjia.com/PHPjc/445794.html techarticle session, in a computer, especially in a network application, is called a conversation. A server traffic is relatively large, because the program needs, the session expiration time is set to 3 hours, resulting in ...