Home > php教程 > php手册 > php 简单定时生成静态页面实现方法

php 简单定时生成静态页面实现方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-25 16:42:48
Original
907 people have browsed it

<?php
function mkhtml() {
    ob_start();
    //输出内容
    $temp = ob_get_contents();
    ob_end_clean();
    $fp = fopen("./index.htm", &#39;w&#39;);
    fwrite($fp, $temp);
}
if (file_exists("./index.htm")) //看静态index.htm文件是否存在
{
    $time = time();
    //文件修改时间和现在时间相差?的话,直接导向htm文件,否则重新生成htm
    if ($time - filemtime("./index.htm") < 600) {
        header("location:phprm.com/main.htm");
    }
}
?>
Copy after login

ob_start():是打开缓冲区的,就是要把您需要生成的静态文件的内容缓存在这里; 

ob_get_contents():是读出缓冲区里的内容,下面有代码为例; 

ob_end_clean():这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来

filemtime() 函数返回文件内容上次的修改时间.

若成功,则时间以 unix 时间戳的方式返回,若失败,则返回 false.

语法:filemtime(filename)


文章地址:

转载随意^^请带上本文地址!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template