キャッシュされたファイルでも、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();
キャッシングを停止した最初の段階です。これにより、実行されていないPHP コードがキャッシュされたファイルに保存されます。この時点では、「キャッシュされていません」が、このコードはキャッシュされたファイルに保存されます。私たちがしたので
$storecodeincache .= ob_get_contents();
ob_end_clean();
キャッシングを終了しました。そして、私たちはやっています
ob_start();
その後(キャッシュが再び開始されます)。しかしその間、PHPキャッシュはオフになっています。このような任意の時点で PHP キャッシュをオフにし、実行されていないPHP コードを「既に実行されたコード」のキャッシュに使用される同じ変数に保存してから、次に進みます (キャッシュを再度オンにして続行します)。