Server performance is slow. The temp folder on drive C contains a large number of files starting with sess. causes and solutions

Source: Internet
Author: User
Tags php session

The problem is found and resolved through a search. Detailed records are provided here for your reference.

1. delete a large number of files in the temp folder

Files starting with sess in the Temporary Folder of temp system are saved by the php session. Because php creates a session but fails to be deleted after expiration, a large number of files are accumulated.

The cleanup method is simple. Create a batch file del_temp.bat and write the following command:

Copy codeThe Code is as follows: del % TEMP %/s/q *.*

After saving the file, double-click it and run it to start deletion (you can also directly input and execute it in the cmd command line)
You can also add it to the startup item so that the system is deleted once after each restart.

Tip:

1. if the execution continues to show that it cannot be performed (this is the first case encountered by Zhiwen studio), it may be that the temp folder and some of the files are in use, then you can create a folder tmp in the same directory and modify the location of the system environment variables temp and tmp. Then restart the system to make the new temporary directory take effect, you can delete and modify the temp file.

2. The temp folder on the server of Zhiwen studio has a memory of 100,000 such files, which has been cleared for several hours. Therefore, stop iis before processing:

Net stop iisadmin disable iis service
Net start iisadmin enable iis service

3. Of course, you do not want to close the website for so long during the processing, so you should perform the following operations in sequence:

1>. Disable iis
2>. Change the default path for saving the session in php (refer to the following content)
3>. Enable iis and check whether all the sites on the server are normal.
4>. Execute del_temp.bat to clean up

2. Modify the php Session save path session. save_path

1. Open the php. ini file and find

"; Session. save_path ="/tmp ""
Change it to a specified location to store the session. For example, change it:

Session. save_path = "c:/tmp/phpsession"
Of course, you can also use the hierarchical directory method, such as the following:

Session. save_path = "5; c:/tmp/phpsession"

For details about the hierarchical directory storage of sessions, refer to the subsequent content

2. Create a folder path: c:/tmp/phpsession

3. Add the internet Guest Account Modification and write permissions for this path (that is, the phpsession folder). Be sure not to grant execution permissions.

4. Start iis and check whether new session files are generated in the directory.

Iii. php session multi-level directory storage solves the efficiency problem of a large number of temporary files

Multi-level session storage can alleviate the Read and Write efficiency problems caused by too many session files in a directory.

Description about sesstion configuration on php.net: http://cn.php.net/manual/zh/ref.session.php

Session. save_path string

Session. save_path defines the parameters passed to the storage processor. If the default files file processor is selected, this value is the path of the file to be created. The default value is/tmp. See session_save_path ().
This command also has an optional N parameter to determine the directory depth of the session file distribution. For example, setting it to '5;/tmp 'will make the created session file and path similar

/Tmp/4/B/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If
To use the N parameter, you must create these directories before using them. In the ext/session directory, a small shell script named mod_files.sh can be used to do this. In addition, if the N parameter is used and N is greater than 0, automatic garbage collection is not performed. For more information, see php. ini.
In addition, if the N parameter is used, make sure that the value of session. save_path is enclosed by double quotation marks "quotes", because the semicolon (;) separator is also an annotation symbol in php. ini.

Refer to the above instructions to define the path for multi-level storage in session. save_path, so we can modify session. save_path in php. ini:

Session. save_path = "2;/data/session_tmp"

In this way, session files are stored in two levels, which is similar

/Data/session_tmp/4/B/sess_4b1e384ad74619bd212e236e52a5a174If

Take the first two characters of the session as the secondary Directory Index, but php does not generate the directory, You need to manually generate it. Here we provide a php script to generate the initial directory.

Copy codeThe Code is as follows: <? Php
$ String = '0123456789abcdefghijklmnopqrstuvwxyz ';
$ Length = strlen ($ string );
Function makeDir ($ param)
{
If (! File_exists ($ param )){
Echo "mkdir". $ param. "\ n ";
Exec ("mkdir". $ param );
}
}

For ($ I = 0; $ I <$ length; $ I ++ ){
For ($ j = 0; $ j <$ length; $ j ++ ){
MakeDir ('/data/session_tmp/'. $ string [$ I]. '/'. $ string [$ j]);
}
}
?>

After the session directory is processed hierarchically, the I/O processing value increases, the http process decreases, and the web processing efficiency improves significantly.

References

Server efficiency problems caused by a large number of session temporary files in the session. save_path directory
Http://wenku.baidu.com/view/b3921d8ea0116c175f0e484e.html
Website failure caused by permission issues in the Temp folder in the iis php Environment
Http://www.jb51.net/article/34301.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.