Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP / MySQL site using caching. What makes this work most of the time?
    primarykey
    data
    text
    <p>Our previous webmaster set up this site and the caching he set up works fine for most browsers but I have found that some versions of Opera don't work and some online SEO tools like <a href="http://www.submitexpress.com/analyzer/" rel="nofollow">Submit Express Analyzer</a>. I suspect that it's an issue with headers. I've read about ob_start("ob_gzhandler") but I'm not sure how I can implement it in this scenario.</p> <p>The site is all controlled by a router file, unique controller files for each type of page and .htaccess. In the router file, the code below is set in place to look for a cached version of the page and load the content, otherwise, load the page.</p> <p>The caching compresses the page content with gzencode and stores it in the database in a cache table with a uri hash. If the cached file exists, the content is pulled from the database.</p> <p>Opera displays a blank page and the Submit Express Test does not recognize a page. I am almost certain that the .htaccess file has nothing to do with the issue. The code below is where I think the issue resides.</p> <pre><code>&lt;?php $loadTime = microtime(true); session_start(); if (!isset($_SESSION['var'])) $_SESSION['var'] = rand(0, 2); if (!isset($_SESSION['var2'])) $_SESSION['var2'] = rand(0, 4); require(dirname(__FILE__).'/config/common.php'); $uri = $_SERVER['REQUEST_URI']; $request = explode('/', substr($uri, 1)); $request = preg_replace('/\..*/', '', $request); $uriHash = sha1($uri); if($uri == '/') //This is the Index... { </code></pre> <p>Irrelevant Index Code</p> <pre><code>} try { // LOOKS FOR CACHE IN DB BASED ON URI $cache = $GLOBALS['db']-&gt;getRow("SELECT * FROM cache_tbl WHERE uri_hash = '$uriHash'"); }catch ( Exception $e ) { $cache = array(); } if ( !empty($cache) &amp;&amp; ($cache['mod_date'] * 60 * 60 * 24) &gt; $loadTime ) { // IF NO CACHE IN DB, SETS HEADERS FOR COMPRESS OR NO COMPRESS $HTTP_ACCEPT_ENCODING = $_SERVER["HTTP_ACCEPT_ENCODING"]; if( headers_sent() ) $encoding = false; else if( strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false ) $encoding = 'x-gzip'; else if( strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false ) $encoding = 'gzip'; else $encoding = false; $compressed = $cache['contents']; if ( $encoding ) { header("Content-Encoding: ".$encoding); echo $compressed; } } else { if ($request[0] == 'venues') { header("HTTP/1.1 301 Moved Permanently"); header('Location: '.HOST.$request[1].'.html'); } </code></pre> <p>More Code</p> <pre><code>if ( // Irrelevant Conditions ) { $contents = ob_get_clean(); echo $contents; $compressed = gzencode($contents, 7); try { Admin::add('cache_tbl', array('uri_hash' =&gt; $uriHash, 'contents' =&gt; $compressed, 'mod_date' =&gt; $loadTime)); } catch(Exception $e) { ; } ob_end_flush(); } } </code></pre> <p>There's a lot going on in this file and I tried to cut out as much stuff as possible to eliminate confusion. Any help is obviously greatly appreciated! Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload