ThinkPHP5 清除缓存
Sonder
2020-04-14
2139字
5分钟
浏览 (2.2k)
/**
* @param null $directory
* @return bool
* @name: clear_cache
* @describe:清除系统缓存
*/
function clear_cache($directory = null)
{
$directory = empty($directory) ? ROOT_PATH . 'runtime/cache/' : $directory;
if (is_dir($directory) == false) {
return false;
}
$handle = opendir($directory);
while (($file = readdir($handle)) !== false) {
if ($file != "." && $file != "..") {
is_dir($directory . '/' . $file) ?
clear_cache($directory . '/' . $file) :
unlink($directory . '/' . $file);
}
}
if (readdir($handle) == false) {
closedir($handle);
rmdir($directory);
}
}
/**
* @param null $directory
* @return bool
* @name: clear_log
* @describe:清除系统日志
*/
function clear_log($directory = null)
{
$directory = empty($directory) ? ROOT_PATH . 'runtime/log/' : $directory;
if (is_dir($directory) == false) {
return false;
}
$handle = opendir($directory);
while (($file = readdir($handle)) !== false) {
if ($file != "." && $file != "..") {
is_dir($directory . '/' . $file) ?
clear_cache($directory . '/' . $file) :
unlink($directory . '/' . $file);
}
}
if (readdir($handle) == false) {
closedir($handle);
rmdir($directory);
}
}
/**
* @param null $directory
* @return bool
* @name: clear_temp
* @describe:刷新系统静态文件
*/
function clear_temp($directory = null)
{
$directory = empty($directory) ? ROOT_PATH . 'runtime/temp/' : $directory;
if (is_dir($directory) == false) {
return false;
}
$handle = opendir($directory);
while (($file = readdir($handle)) !== false) {
if ($file != "." && $file != "..") {
is_dir($directory . '/' . $file) ?
clear_cache($directory . '/' . $file) :
unlink($directory . '/' . $file);
}
}
if (readdir($handle) == false) {
closedir($handle);
rmdir($directory);
}
}