用缓存实现静态页面的测试
程序员文章站
2023-11-26 15:58:40
<?php
function createshtml()
{
ob_start(array("callback_createshtml","callback_gotoshtml"));
}
function callback_createshtml($buffer)[
{
$page = intval(@$_request["page"]);
$filename = $_server['document_root'] . dirname($_server['php_self']) . "/" . basename($_server['php_self'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";
$fp = fopen($filename,"wb");
fwrite($fp,$buffer);
fclose($fp);
return $buffer;
}
function callback_gotoshtml($buffer)
{
$page = intval(@$_request["page"]);
$filename = basename($_server['php_self'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";
header("location:" . $filename);
return $buffer;
}
function gotoshtml()
{
$page = intval(@$_request["page"]);
$filename = basename($_server['php_self'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";
if(file_exists($filename))
header("location:" . $filename);
}
function deleteshtml($filename=null)
{
if(is_null($filename))
$filename = $_server['document_root'] . $_server['php_self'];
if($filename[0]=="/")
$filename = $_server['document_root'] . $filename;
$path = dirname($filename);
$dir = dir($path);
$patten = "/^" . basename($filename, ".php") . "(_[0-9]+)?.htm/";
while(($entry = $dir->read())!==false)
{
if(is_file($path . "/" .$entry) && preg_match($patten,$entry))
unlink ($path . "/" . $entry);
}
}
createshtml();
echo "这是静态生成的页面!$page";
gotoshtml();
deleteshtml();
?>
function createshtml()
{
ob_start(array("callback_createshtml","callback_gotoshtml"));
}
function callback_createshtml($buffer)[
{
$page = intval(@$_request["page"]);
$filename = $_server['document_root'] . dirname($_server['php_self']) . "/" . basename($_server['php_self'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";
$fp = fopen($filename,"wb");
fwrite($fp,$buffer);
fclose($fp);
return $buffer;
}
function callback_gotoshtml($buffer)
{
$page = intval(@$_request["page"]);
$filename = basename($_server['php_self'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";
header("location:" . $filename);
return $buffer;
}
function gotoshtml()
{
$page = intval(@$_request["page"]);
$filename = basename($_server['php_self'],".php") . ($page==0 ? "" : "_" . strval($page)) . ".htm";
if(file_exists($filename))
header("location:" . $filename);
}
function deleteshtml($filename=null)
{
if(is_null($filename))
$filename = $_server['document_root'] . $_server['php_self'];
if($filename[0]=="/")
$filename = $_server['document_root'] . $filename;
$path = dirname($filename);
$dir = dir($path);
$patten = "/^" . basename($filename, ".php") . "(_[0-9]+)?.htm/";
while(($entry = $dir->read())!==false)
{
if(is_file($path . "/" .$entry) && preg_match($patten,$entry))
unlink ($path . "/" . $entry);
}
}
createshtml();
echo "这是静态生成的页面!$page";
gotoshtml();
deleteshtml();
?>
上一篇: CoreIDRAW(CDR)设计打造质感的立体字实例教程
下一篇: 使用Python来开发微信功能