Server performance slows down the C disk Temp folder exists a large number of sess opening file problems and solutions _win Server

Source: Internet
Author: User
Tags garbage collection ini mkdir php session php script save file

The problem was found and resolved through a search, which is documented in detail for reference.

The deletion of a large number of files in the Temp folder

The file that begins with Sess in temp system temporary folder, is PHP's session save file, because PHP establishes session but after expired did not delete successfully, then caused a lot of file accumulation.

The cleanup method is simple, creating a new batch file, Del_temp.bat, which writes the following command:

Copy Code code as follows:

Del%TEMP%/s/q *.*

When you double-click to run, you start the delete process (or you can enter execution directly on the cmd command line)
You can also add it to the boot entry to perform a delete process every time the system is restarted.

Tips:

1. If execution has been shown to be impossible (as is the case with the log studio first), you may have the Temp folder and some of its files in use, so you can create a new folder tmp in the same directory, and then modify the location of the system environment variable TEMP and TMP. Then reboot the system so that the new temporary directory takes effect, at which point the temp file can be arbitrarily deleted.

2. There are hundreds of thousands of such files in the server temp folder of the blog studio, which have been cleaned up for several hours before completing. It is therefore necessary to stop IIS before processing:

net stop IISAdmin shut down the IIS service
net start IISAdmin to open the IIS service

3. Of course, you do not want to be in the process of keeping the site closed so long, so you should do the operation is:

1>. Turn off IIS
2>. Change the default path for PHP save session (refer to the following)
3>. Turn on IIS to check that all sites on the server are normal
4>. Perform del_temp.bat cleanup

Second, modify the PHP session save path Session.save_path

1. Open php.ini file and find

"; Session.save_path ="/tmp ""
Modify it to the specified location to store the session, for example, to the log studio to:

Session.save_path = "C:/tmp/phpsession"
Of course, you can also use a hierarchical directory, for example, instead:

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

About the session of the hierarchical directory storage please refer to the follow-up content detailed

2. New Folder path: C:/tmp/phpsession

3. Add the Internet Guest account modification and write permissions for the path (that is, the Phpsession folder), and note that it is best not to give execution permissions.

4. Start IIS to see if the directory will have a new session file to produce.

Third, PHP session multilevel directory Storage to solve a large number of temporary file efficiency problems

Session multilevel storage can alleviate the problem of reading and writing efficiency caused by too many session files in a directory.

Instructions on the php.net for sesstion configuration: http://cn.php.net/manual/zh/ref.session.php

Session.save_path string

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

/TMP/4/B/1/E/3/sess_4b1e384ad74619bd212e236e52a5a174if
To use the N parameter, you must first create the directories before you use them. In the Ext/session directory there is a small shell script called mod_files.sh that can be used to do this. Also note that if you use the n parameter and N is greater than 0, automatic garbage collection will not be performed and more information is php.ini.
In addition, if you use the N parameter, be sure to enclose the value of Session.save_path in double quotes "quotes" because the delimiter semicolon (;) is also an annotation symbol in php.ini.

Refer to the above instructions, in the definition of Session.save_path can be defined multi-level storage path, so we can modify the php.ini in the Session.save_path as follows:

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

This divides the session file into level two storage, which is similar to

/data/session_tmp/4/b/sess_4b1e384ad74619bd212e236e52a5a174if

Take the first two characters of the session as a level two directory index, but PHP does not generate a directory, you need to manually build, here provides a PHP script to generate the initial directory.

Copy Code code 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 Session Directory classification processing, the IO processing value increases, the HTTP process reduces, the web processing efficiency is obviously improved

Related reference

Session.save_path directory large number of Session temp files bring server efficiency issues
Http://wenku.baidu.com/view/b3921d8ea0116c175f0e484e.html
Web site failure caused by permission problems with the IIS PHP Environment Temp Folder
Http://www.jb51.net/article/34301.htm

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.