ITPub博客

首页 > IT职业 > IT职场 > php页面缓存的使用方法

php页面缓存的使用方法

IT职场 作者:gabbro 时间:2021-09-09 09:19:49 0 删除 编辑

    function cache_start($dir,$expiretime){

        $filename = $dir.'\'.sha1($_SERVER['REQUEST_URI']).'.html';

        ob_start();

        

        if(file_exists($filename) && (time()- filemtime($filename)

            include($filename);

            ob_end_flush();

            exit();

        }

        mkdir($dir);

    }

    function cache_end($dir){

        $filename = $dir.'\'.sha1($_SERVER['REQUEST_URI']).'.html';

        echo $filename;

        

        $fp = fopen($filename,'w');

        fwrite($fp,ob_get_contents());

        fclose($fp);

        

        ob_end_flush();

    

    }

$dir = "D:\\php";

cache_start($dir, 10);

cache_end($dir);

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2873/viewspace-2809507/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: Validator.php-4
请登录后发表评论 登录
全部评论

注册时间:2019-08-19

  • 博文量
    85
  • 访问量
    726