首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ PHP / 文章详情

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);
    }
}
下一篇 / 获取内容中的图片

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)