PHP: Caching system creates an extra 404 error file -


i have caching system on php website. works charm, whenever cache file created, cache file generated 404 page well.

example: visit page-2, caching system detects new cache-file needs created. creates file page-2 (and serve other people late), file 404 page.

question: why 404 cache-page created?

i tried find out why, stuck ...

this code header include:

<?php $url = $_server["script_name"]; $break = explode('/', $url); $file = $break[count($break) - 1];  $cachefile = $_server['http_host'].$_server['request_uri']; $urlpage = $cachefile; $cachefile = md5($cachefile).".html";      if (!empty($param1) ){$cachetime = 86400;}     elseif (!empty($param2) ){$cachetime = 86400;}     elseif (!empty($param3) ){$cachetime = 86400;}     elseif ($page == 'random' ){$cachetime = 0;}     else {$cachetime = 60;}  $cachefileloc = __dir__ . '/../_cache/' .$cachefile;  // serve cache if younger $cachetime     if (file_exists($cachefileloc) && time() - $cachetime < filemtime($cachefileloc)) {         include($cachefileloc);         exit; } ob_start(); // start output buffer <my html-output starts here> 

this code footer include:

<?php // cache contents file $cached = fopen(__dir__ . '/../_cache/' .$cachefile, "w"); fwrite($cached, ob_get_contents()); fclose($cached); ob_end_flush(); // send output browser ?> 

any thoughts on issue?

extra information: - 404 page created after has created cache file. - 404 page not created, looks googlebot visit not creating 404.

my .htaccess:

errordocument 404 http://www.example.com/404.php  ################################################### # turn rewriteengine on.                      # ################################################### rewriteengine on rewritecond %{http_host} !^www\. rewriterule ^(.*)$ http://www.%{http_host}/$1 [r=301,l] rewriterule ^(/)$ /index.php?p= [l] rewriterule ^(/)?contact/?$ /index.php?p=contact [l] rewriterule ^(/)?aboutus/?$ /index.php?p=aboutus [l] rewriterule ^(/)?links/?$ /index.php?p=links [l] rewriterule ^(/)?searchresults/?$ /index.php?p=searchresults [l] rewriterule ^(/)?contactmail/?$ /index.php?p=mailing [l] rewriterule ^(/)?random/?$ /index.php?p=random [l] rewriterule ^(/)?recent/?$ /index.php?p=recent [l] rewriterule ^(/)?trends/?$ /index.php?p=trends [l] rewriterule ^(/)?cookies/?$ /index.php?p=cookies [l] rewriterule ^bam/([^/\.]+)/?$ /artists.php?a=$1 [l] rewriterule ^bam/([^/\.]+)/([^/\.]+)/?$ /artists.php?a=$1&s=$2 [l] rewriterule ^browse/([^/\.]+)/?$ /browse.php?l=$1 [l] 

it's query strings passed 404 handler script well, results in generation of new cache file. test whether that's indeed case:

//$cachefile = $_server['http_host'].$_server['request_uri']; $cachefile = $_server['http_host'] . strtok($_server["request_uri"],'?'); $urlpage = $cachefile; $cachefile = md5($cachefile).".html"; 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -