用缓存实现静态页面的测试

2018-09-07 14:31

阅读:263

  <?php
functionCreateShtml()

{

ob_start(array(callback_CreateShtml,callback_GoToShtml));

}

functioncallback_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;

}

functioncallback_GoToShtml($buffer)

{

$page=intval(@$_REQUEST[page]);

$fileName=basename($_SERVER[PHP_SELF],.php).($page==0?:_.strval($page))..htm;

header(location:.$fileName);

return$buffer;

}

functionGoToShtml()

{

$page=intval(@$_REQUEST[page]);

$fileName=basename($_SERVER[PHP_SELF],.php).($page==0?:_.strval($page))..htm;

if(file_exists($fileName))

header(location:.$fileName);

}

functionDeleteShtml($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();
?>


评论


亲,登录后才可以留言!