Hi guys,

I need a help for caching web pages.

My website is driven by database and updated everytime (sometimes minute by minute sometime hour by hour, never know). Content and some information comes from database as well. There are also some queries run behind for logging purposes based on users' actions and database is updated (I guess this wouldn't be a problem in any cases since it only does INSERT instead of SELECT).

I want make the site faster by using caching techniques. I know that if I do it wrong my site will show old content from cache.

Is tehere any example for me to use or to understand how I should do it?

Thanks in advance

Recommended Answers

All 2 Replies

Hello, caching in PHP is one thing that you must try yourself all the options and create measurable test for them in order to decide. In my point of view there are two separated layers of cashing. Application scope and “thread” scope. While application scope cashing, cash objects for use in all users (in a MVC pattern could cash the static variables of a Controller) a “thread” scope cashing, cash objects for use only for the specific “thread” – visit (e.g. public variables of a Controller class in a MVC pattern) .

The dissociation of this two deferent scopes of cashing could help peroformance and logic, for example the content of a dynamic page is application scope while shoping cart items or user log info could cashed through “thread” scope. I can share with you what my tests have stated , but since the result is deferent than the known “PHP isn’t for caching” you should make your own test too.

For application scope cashing the best way is through file system (especially when you use a MVC pattern and you can cash only the statics of a Controller in a separated file (of course out of public_html and of course being sure that you don’t allow access to it to others than your application)) , that is true if you unserialize the objects when you change them and have only to serialize them each time you access them (usually the person you change a dynamic page of an application can take the cost of unserialize). For “thread” scope cashing the best way is session as long as you don’t you use the despicable unserialize (serialize) (you have your autoload sated proper).

I mentioned that there are many opinions about cashing with PHP but you should find your way with tries and tests. Hoped that a helped…

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.