Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows/Temp directory is full of Php Session's files that block the server

Hello everyone I'm Italian and I apologize in advance for errors that read as follows :)

They were dark days for my server and I was going crazy to understand what could be the problem. I thought that the database was badly configured, or that the hard disk could have some troubles, and I was thinking of changing server. While it was testing the harddisk with defragmentation and scandisk (not runnable), I decided to open CCleaner and the miracle has happened. The Windows / Temp folder was completely blocked and you could not even open IT. CCleaner has cleaned up in ten hours the folder :') Ten hours for one folder!

After a day of cleaning, this morning I went to check it and inside there were 18000 0kb files or max 10kb all called "sess_0a5u2ou87 ........." (sess_ is prefixed, and i think are followed by md5).

When I opened one of them, I found in it the session variables of my website's users.

var|s:1:"2";timeout|i:1403338177;id|s:1:"1";name|s:17:"Foo";

Here is shown how I create sessions:

//create session
session_start();
$_SESSION['var'] = $var;
$_SESSION['timeout'] = time();

//work with session
public static function resetVar(){
   if(isset($_SESSION['var'])){
            unset($_SESSION['var']);
        }
}

//destroy session
session_start();  
if(isset($_SESSION['timeout'])) {       
    $duration = time() - (int)$_SESSION['timeout'];
    if($duration > 6000) {
        session_destroy(); 
    header("Location: index.php");
    }
    $_SESSION['timeout'] = time();
}     

Can anyone help me to understand this?

like image 302
Peppinosh Avatar asked Jun 21 '14 09:06

Peppinosh


2 Answers

I was able to solve the problem. it was enough to change the folder where PHP saves the session.. changing it, the files "sess_..." older than one hour, will be automatically deleted! I think Php tried to delete the files in the Windows/Temp folder but probably for permission problems, he could not.

You can change the path in the php settings (php.ini) by changing the value of "session.save_path"

like image 97
Peppinosh Avatar answered Oct 10 '22 16:10

Peppinosh


I had the same issue but I was seeing a PHP MYSQL PDO Driver missing error.

 could not find driver

Only after some digging did I find that the session directory had 15k files. After delete, all good.

Checkout this php var that manages the lifetime of session files;

 session.gc_maxlifetime

http://ar.php.net/manual/en/session.configuration.php.

like image 30
PodTech.io Avatar answered Oct 10 '22 16:10

PodTech.io