Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:20:43+00:00 2026-05-31T16:20:43+00:00

Our previous webmaster set up this site and the caching he set up works

  • 0

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 Submit Express Analyzer. 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.

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.

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.

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.

<?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...
{

Irrelevant Index Code

}
try
{ // LOOKS FOR CACHE IN DB BASED ON URI
$cache = $GLOBALS['db']->getRow("SELECT * FROM cache_tbl WHERE uri_hash = '$uriHash'");
}catch ( Exception $e ) {
$cache = array();
}

if ( !empty($cache) && ($cache['mod_date'] * 60 * 60 * 24) > $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');
}

More Code

if ( // Irrelevant Conditions ) {
    $contents = ob_get_clean();
    echo $contents;

    $compressed = gzencode($contents, 7);

    try {
        Admin::add('cache_tbl', array('uri_hash' => $uriHash, 'contents' => $compressed, 'mod_date' => $loadTime));
    } catch(Exception $e) { ; }

    ob_end_flush(); 
}
}

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:20:44+00:00Added an answer on May 31, 2026 at 4:20 pm

    Okay, this one looks nasty.

    Firstly, the error handling is awful – swallowing errors like that in a code section that gets called on every page sucks.

    Secondly, most web servers will handle GZIP etc. pretty much out of the box – there’s really no reason to invent this yourself.

    Thirdly, it may be because of the way you’ve split up the code, but I think that in the “IF” block below, there’s no case for echoing out the content if the current browser does not accept compressed content.

    if ( !empty($cache) && ($cache['mod_date'] * 60 * 60 * 24) > $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;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some redirects in place from our previous site that used CakePHP. The
can anyone help. I have recently moved servers, its IIS7 rather that our previous
We have a custom attribute that our previous developer (recently disappeared) has created in
In C# our maintainance project, we observered that the previous company has a root
I've found previous programmers using cfstoredproc in our existing project about insert records into
I currently had a problem similar to this previous question: Why would our Java
This is one of those 'oh my god' moments. The previous programmer in our
Our previous programmer set the wrong collation in a table (Mysql). He set it
We've just updated PHP on our server, for the most part everything is fine,
We want to update an existing Application but unfortunately we have a problem. Our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.