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 6361985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:50:55+00:00 2026-05-24T23:50:55+00:00

i have read a bit around in the internet about the php cache. at

  • 0

i have read a bit around in the internet about the php cache.
at the moment i am using, this system to cache my pages:

This is putted on the start of the page

<?php

    // Settings
    $cachedir = 'cache/'; // Directory to cache files in (keep outside web root)
    $cachetime = 600; // Seconds to cache files for
    $cacheext = 'html'; // Extension to give cached files (usually cache, htm, txt)

    // Ignore List
    $ignore_list = array(
        'addedbytes.com/rss.php',
        'addedbytes.com/search/'
    );

    // Script
    $page = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // Requested page
    $cachefile = $cachedir . md5($page) . '.' . $cacheext; // Cache file to either load or create

    $ignore_page = false;
    for ($i = 0; $i < count($ignore_list); $i++) {
        $ignore_page = (strpos($page, $ignore_list[$i]) !== false) ? true : $ignore_page;
    }

    $cachefile_created = ((@file_exists($cachefile)) and ($ignore_page === false)) ? @filemtime($cachefile) : 0;
    @clearstatcache();

    // Show file from cache if still valid
    if (time() - $cachetime < $cachefile_created) {

        //ob_start('ob_gzhandler');
        @readfile($cachefile);
        //ob_end_flush();
        exit();

    }

    // If we're still here, we need to generate a cache file

    ob_start();

?>

MY HTML CODE Goes here ………….

and the code below is at the footer of my page.

<?php

    // Now the script has run, generate a new cache file
    $fp = @fopen($cachefile, 'w'); 

    // save the contents of output buffer to the file
    @fwrite($fp, ob_get_contents());
    @fclose($fp); 

    ob_end_flush(); 

?>

There are some things that i need and this code dont have them :

  • gzip
  • the expired cache is not autodeleted after it expire.

Also wanted to ask, if this code is secure to use , if some one can suggest a better one or something to improve the current code it will be just great

Thank you fro reading this post.
Best Regards
Meo

  • 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-24T23:50:56+00:00Added an answer on May 24, 2026 at 11:50 pm
    ….
      // Show file from cache if still valid
      if (time() - $cachetime < $cachefile_created) {
    
          //ob_start('ob_gzhandler');
          echo gzuncompress(file_get_contents($cachefile));
          //ob_end_flush();
          exit();
    
      } else {
        if(file_exists($cachefile) && is_writable($cachefile)) unlink($cachefile)
      }            
    ….
    

    and

        // Now the script has run, generate a new cache file
        $fp = @fopen($cachefile, 'w'); 
    
        // save the contents of output buffer to the file
        @fwrite($fp, gzcompress(ob_get_contents(), 9));
        @fclose($fp); 
    
        ob_end_flush(); 
    
    ?>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Python. I've read a bit about this and can't seem to wrap
I've read around quite a bit but haven't found a definitive answer. I have
I have read this post about how to test private methods. I usually do
I have a question about moving wordpress sites around. I've read most of the
I have read around quite a bit now and think that the following is
I want to come up with a language syntax. I have read a bit
I have read about partial methods in the latest C# language specification , so
I have read that using database keys in a URL is a bad thing
I have read the documentation on this and I think I understand. An AutoResetEvent
I have been programming iPhone SDK for around 6 months but am a bit

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.