Server performance slowed down c disk temp folder has a large number of sess beginning file problems and solutions

  • 2020-05-09 19:39:05
  • OfStack

The problem was found and solved through the search, and detailed records are made here for your reference.

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

The files starting with sess exist in the temporary folder of temp system, which is session of php to save files. Since php established session but failed to delete it after its expiration, a large number of files are accumulated.

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


del %TEMP% /s /q *.*

After saving, double-click to run to start the deletion process (you can also enter execution directly on the cmd command line)
You can also add it to the boot-up TAB so that the delete process is performed once every time the system is restarted.

Tip:

1. If this 1 shows that can't be straight (tzu word studio met first that is the case), could be temp folder and its part of the file is in use, so you can be in the same directory a new folder tmp, then modify the system environment variables temp and tmp position to do so, and then restart the system make the new temporary directory effect, can be arbitrary deletion for temp file at this time.

2. There are hundreds of thousands of such files in the server temp folder of zhiwen studio, which took several hours to clean up. Therefore, iis should be stopped before processing:

net stop iisadmin shut down iis service
net start iisadmin opens iis service

3. Of course, you don't want to keep your site down for so long in the process, so you should follow these steps:

1 > . Close iis
2 > . Change the default path for php to save session (see below)
3 > . Open iis and check whether all sites of the server are normal
4 > . Perform del_temp.bat to clean up

2. Modify the Session save path of php, session.save_path

1. Open php.ini file and find it

"; session. save_path = "/ tmp" "
Change it to the specified location for storing session, for example, zhiwen studio changed it to:

session.save_path = "c:/tmp/phpsession"
Of course, you can also use a hierarchical directory, such as this:

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

Please refer to the following details for the classification directory of session

2. New folder path: c:/tmp/phpsession

3. Add modify and write permissions to internet guest accounts in this path (i.e. phpsession folder). It is best not to grant execution permissions.
 

4. Launch iis and see if any new session files are generated in this directory.

3. php's session multilevel directory storage solves the efficiency problem of a large number of temporary files

session multi-level storage can alleviate the read/write efficiency problem caused by too many session files in one directory.

On php. net against sesstion configuration related instructions: 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 to create the file. 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, set it 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 create these directories before you use them. In the ext/session directory there is a small shell script called mod_files.sh that you can use to do this. Also note that if the N parameter is used and N is greater than 0, automatic garbage collection will not be performed. See php.ini for more information.
Also, if the N parameter is used, be sure to enclose the session.save_path value in double quotation marks "quotes", because the delimiter semicolon (;) It is also a comment symbol in php.ini.

According to the above instructions, in the definition of session.save_path, we can define the path of multilevel storage, so we can modify session.save_path in php.ini as follows:

session. save_path = "2; / data session_tmp"

The session file is thus split into two levels, similar to

/data/session_tmp/4/b/sess_4b1e384ad74619bd212e236e52a5a174If

Take the first two characters of session as the level 2 directory index, but php does not generate the directory, you need to generate it by yourself, here we provide an php script to generate the initial directory.


<?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 classification of session directory, the processing value of IO increased, the process of http decreased, and the processing efficiency of web improved significantly

Relevant reference

session.save_path directory large number of session temporary files caused server efficiency problems
http://wenku.baidu.com/view/b3921d8ea0116c175f0e484e.html
A website failure caused by permission issues with the IIS PHP environment Temp folder
//www.ofstack.com/article/34301.htm


Related articles: