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

  • Home
  • SEARCH
  • 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 46109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:54:52+00:00 2026-05-10T15:54:52+00:00

I want to implement a two-pass cache system: The first pass generates a PHP

  • 0

I want to implement a two-pass cache system:

  • The first pass generates a PHP file, with all of the common stuff (e.g. news items), hardcoded. The database then has a cache table to link these with the pages (eg ‘index.php page=1 style=default’), the database also stores an uptodate field, which if false causes the first pass to rerun the next time the page is viewed.

  • The second pass fills in the minor details, such as how long ago something(?) was, and mutable items like ‘You are logged in as…’.

However I’m not sure on a efficient implementation, that supports both cached and non-cached (e.g., search) pages, without a lot of code and several queries.

Right now each time the page is loaded the PHP script is run regenerating the page. For pages like search this is fine, because most searches are different, but for other pages such as the index this is virtually the same for each hit, yet generates a large number of queries and is quite a long script.

The problem is some parts of the page do change on a per-user basis, such as the ‘You are logged in as…’ section, so simply saving the generated pages would still result in 10,000’s of nearly identical pages.

The main concern is with reducing the load on the server, since I’m on shared hosting and at this point can’t afford to upgrade, but the site is using a sizeable portion of the servers CPU + putting a fair load on the MySQL server.

So basically minimising how much has to be done for each page request, and not regenerating stuff like the news items on the index all the time seems a good start, compared to say search which is a far less static page.

I actually considered hard coding the news items as plain HTML, but then that means maintaining them in several places (since they may be used for searches and the comments are on a page dedicated to that news item (i.e. news.php), etc).

  • 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. 2026-05-10T15:54:53+00:00Added an answer on May 10, 2026 at 3:54 pm

    I second Ken’s rec of PEAR’s Cache_Lite library, you can use it to easily cache either parts of pages or entire pages.

    If you’re running your own server(s), I’d strongly recommend memcached instead. It’s much faster since it runs entirely in memory and is used extensively by a lot of high-volume sites. It’s a very easy, stable, trouble-free daemon to run. In terms of your PHP code, you’d use it much the same way as Cache_Lite, to cache various page sections or full pages (or other arbitrary blobs of data), and it’s very easy to use since PHP has a memcache interface built in.

    For super high-traffic full-page caching, take a look at doing Varnish or Squid as a caching reverse proxy server. (Pages that get served by Varnish are going to come out easily 100x faster than anything that hits the PHP interpreter.)

    Keep in mind with caching, you really only need to cache things that are being frequently accessed. Sometimes it can be a trap to develop a really sophisticated caching strategy when you don’t really need it. For a page like your home page that’s getting hit several times a second, you definitely want to optimize it for speed; for a page that gets maybe a few hits an hour, like a month-old blog post, it’s a bad idea to cache it, you only waste your time and make things more complicated and bug-prone.

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

Sidebar

Ask A Question

Stats

  • Questions 73k
  • Answers 73k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You could make use of the For task from the… May 11, 2026 at 2:08 pm
  • added an answer The standard requires that certain types have minimum sizes (short… May 11, 2026 at 2:08 pm
  • added an answer Your impression is correct. Seaside is designed for what I… May 11, 2026 at 2:08 pm

Related Questions

I want to implement a paperless filing system and was looking to use WIA
I want to implement a simple debug log, which consists of a table into
I want to implement a docking library in wpf with behavior similar to Adobe
I want to implement a simple 2 part FormWizard. Form 1 will by dynamically
I'm writing this question with reference to this one which I wrote yesterday. After
I want to implement drag and drop between two components within the same JVM.
I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application
I have a vector-like class that contains an array of objects of type T

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.