您仍然可以调用PHP代码和变量,即使在高速缓存文件。有一种方法可以“绕过”这一点。我不知道你缓存究竟如何,但使用PHP是这样的:
<?php
/*start caching*/
ob_start();
SOME PHP OR HTML CODE HERE
/*this will store "already executed code" in cache and clears the buffer*/
$storecodeincache .= ob_get_contents();
ob_end_clean();
/*now at this point there is a piece of code we want to execute later, so we
use the same variable, but we store store PHP code we want execute later like this:*/
$storecodeincache .= 'SOMEPHPCODE';
/*we start regular caching again*/
ob_start();
SOME PHP OR HTML CODE HERE
/*we are finished, we want to store the rest*/
$storecodeincache .= ob_get_contents();
ob_end_clean();
/*not neccessary, just when you call the script you see what has been cached*/
echo $storecodeincache ;
/*write all cached content into the file*/
$handle = fopen('safe://pathwhereyousavethecachedcontent', 'w');
fwrite($handle, $storecodeincache);
fclose($handle);
?>
最重要的部分是$storecodeincache .= ob_get_contents();
在beggining当我们停止缓存 - 此存储非执行 PHP代码到缓存的文件中 - 请注意,在这一点上,我们是“不缓存”,但我们将此代码存储到缓存文件anywa!因为我们做过
$storecodeincache .= ob_get_contents();
ob_end_clean();
哪个结束了缓存。我们正在做
ob_start();
之后(它开始再次缓存)。但在两者之间,PHP缓存已关闭。您可以在任何时候关闭PHP缓存,将任何未执行的 PHP代码存储到用于缓存“已执行代码”的相同变量中,然后继续(再次打开缓存并继续)。
将所有这些存储在名为'header-info.html'的文件中,然后使用'<?php include'header-info.html'; PHP文件不会被缓存,它们通常是在html请求中动态运行的。缓存一个PHP页面确实有点挫败目的,你可以使用.html代替。 – mawburn
你不需要排除这些项目从非iphones它罚款,如果他们在那里为其他浏览器 – cmorrissey