Bu sınıfla belirttiğiniz sayfa belirttiğiniz dosyada önbellek şeklinde tutulur. Belirlediğiniz süre içerisindeki tekrar ziyarette site kayıtlı önbellekten çağrıldığı için sayfa daha hızlı açılmış olur
<?phpclass onbellek{var $periyot;var $sayfa;var $onbellekdosyasi;function uygula() {clearstatcache();if (file_exists($this->onbellekdosyasi)){if((time() - filemtime($this->onbellekdosyasi))>= $this->periyot){$this->guncelle();}elseif ($f= fopen($this->onbellekdosyasi,"r")){$icerik = fread($f, filesize($this->onbellekdosyasi));fclose($f);echo $icerik;}}else{$this->guncelle();}}function guncelle(){if($icerik = implode("",file($this->sayfa))){if($w = fopen($this->onbellekdosyasi,"w")){fwrite($w,$icerik);fclose($w);$this->uygula();}else{echo "Yazma için önbellek dosyası açılamıyor";}}else{echo "İçerik kapma komut dosyanız çalıştırılamıyor";}}}$b=new onbellek;$b->sayfa = 'http://www.ulusanyazilim.com/';$b->onbellekdosyasi="test.cache";$b->periyot=60;$b->uygula();?>
test.cache içeriği http://www.ulusanyazilim.com/ içeriği ile aynıdır. Çıktı da aynı şekildedir.