Home > Backend Development > PHP Tutorial > php 首页定时生成静态页面

php 首页定时生成静态页面

WBOY
Release: 2016-06-23 13:26:59
Original
1005 people have browsed it

往往首页的js,商务通代码加的太多,导致页面访问速度变慢,可以把首页有动态变为静态进行访问,访问速度会有所提升,不过如果更新首页数据,并不能及时更新,而是你规定的时间内固定更新一次

代码如下:

$nowtime=time();
$pastsec=$nowtime-$_GET["t"];
if ($pastsec{
exit; //5分钟更新一次,时间可以自己调整
}
ob_start(); //打开缓冲区
include("index.php");
$content=ob_get_contents(); //得到缓冲区的内容
$content.="\n"; //加上调用更新程序的代码

file_put_contents("index.html",$content);

if (!function_exists("file_put_contents"))
{
function file_put_contents($fn,$fs)
{
$fp=fopen($fn,"w");
fputs($fp,$fs);
fclose($fp);   
}
}
?>

合肥亿鑫工作室提供

source:php.cn
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template