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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:12:25+00:00 2026-05-29T11:12:25+00:00

I have sections on a page that require a fair amount of resources that

  • 0

I have sections on a page that require a fair amount of resources that I would like to cache, here is an example of the page.

[=== Some Static HTML ===]
[=== PHP Script 1 ===]
[=== Some Static HTML ===]
[=== PHP Script 2 ===]

I would like to put “PHP Script 1” into a cache file eg script1.html and include it rather than processing the whole script, and the same for Script 2.

The problem I have is I can cache the whole page easily and it works but I would like to just cache specific parts (as above) because some things like user session data needs to be live.

I have this class that is meant to be able to stop and start the buffer so I can pull out specific parts without breaking the rest of the page however it doesn’t do what I want.
http://pastebin.com/Ua6DDExw

I would like to be able to go like this below, while it would store the section in a file with a simple php inlcude rather hitting the database.

HTML Content

<?php
$cache->start_buffer("cache_name");
// PHP Script
$cache->end_buffer("cache_name");
?>

HTML Content

<?php
$cache->start_buffer("cache_name");
// PHP Script
$cache->end_buffer("cache_name");
?>

I don’t have access to memcache or anything else like that because this will be going on shared hosting.

Any help would be great,
Thanks

  • 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-29T11:12:26+00:00Added an answer on May 29, 2026 at 11:12 am

    look into using ob_start() and ob_flush() It does what you are looking to do. You’ll need to manually write it to a file. There are cache.php classes out in the wild as well.

    http://php.net/manual/en/function.ob-start.php

    <?php  
    
      $cache_time = 3600; // Time in seconds to keep a page cached  
      $cache_folder = '/cache'; // Folder to store cached files (no trailing slash)  
    
      // Think outside the box the original said to use the URI instead use something else.
      $cache_filename = $cache_folder.md5(",MyUniqueStringForMyCode"); // Location to lookup or store cached file  
    
      //Check to see if this file has already been cached  
      // If it has get and store the file creation time  
      $cache_created  = (file_exists($cache_file_name)) ? filemtime($this->filename) : 0;
    
      if ((time() - $cache_created) < $cache_time) {  
        $storedData = readCacheFile($cache_filename);
      }
      else
      {
    
        // Alternatively you can ignore the ob_start/get_contents/end_flush code 
        // and just call a function and store it directly to the variable.
        // Start saving stuff
        ob_start();  
    
        /** do your work here echoing data to the screen */
    
        $storedData = ob_get_contents();
        ob_end_flush();
    
        // create the cachefile for the data.
        createCacheFile($cache_filename);
      }
    
    
      // Do stuff with $storedData.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On a blog detail page, I have a tags section. The html looks like:
I have a div like this <section class=item_container> <article class=item> <h2>Page Title</h2> <p><a class=delete_page
So in my string, I have certain sections with hashes. For example, consider the
When I have a table view with some sections which have their own headers
I have an edit page that fills the content with the original content from
When I have three divs that all have float left I want the sections
I have an Asp.net page which requires certain sections to be partially updated automatically
I have a top-level _Layout.cshtml that looks something like this: <html> <head> @RenderSection(Header, required:
We have some JavaScript code that resizes <div/> elements (adjusts height/width/padding/margin etc.) based on
I have a layout page within that layout I have used a partial view,

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.