<?php
/* ÀÛ¼º : howcode.co.kr ±è¼º´ë 2018-02-03 */
/* ¸¶À½´ë·Î ÆÛ°¡µµ µË´Ï´Ù. */
set_time_limit(0);
ini_set('max_execution_time', 300000); 
ini_set('mysql.connect_timeout', 90000);
ini_set('mysql.connect_timeout', 90000);
date_default_timezone_set('Asia/Seoul');
if (!isset($config)) $config=array();
$config['show']=false;
//$config['show']=true;

ar_check_dir("/home");
ar_check_dir("/home2");

function ar_check_dir($path) {
        global $config;
        $handle = @opendir($path);
        if (!$handle) return;
        //if ($config['show']) echo "path:({$config['ar_count_path']}) $path\n";
        if (strstr($path,'/data/session')) {
			if ($config['show']) echo "$path\n";
        }

        while ($file = readdir($handle))
        {
                $filename=$path.'/'.$file;
                if($file == "."||$file == "..") continue;
                if (is_dir($filename)) {
                        ar_check_dir($filename);
                }
                else if (strstr($path,'/data/session')&&strstr($file,'sess_')) {
                        ar_check_file($filename);
                }
        }
        closedir($handle);
}


function ar_check_file($filename) {
	global $config;
	if (strstr($filename,'.php')) {
			echo "ERROR : in .php $filename\n";
			return;
	}
	if (!strstr($filename,'sess_')) return;
	$t=filemtime($filename);
	if ($t<time()-24*3600) {
			if ($config['show']) echo "delete $filename ",date("Y-m-d H:i:s",$t),"\n";
			@unlink($filename);
	}
}
