Forum Moderators: coopster
I have a large section of my website that is created using php/mysql. Some pages require multiple queries to the database. This section of my website is entirely static, besides the occassional update.
It only makes sense that I should cache these pages and deliver them as static pages. Is there a built in method in php to do this? I am on a shared server and am limited on what I can use to do this.
On the flip side, am I really taxing the server by making these queries or is it not really a big deal these days. For example, my pages are very simple next to the complexity of phpbb. Even my worst script only calls about 10 times to the database to pull the information for the page.
Perhaps you could lighten the load by using an iframe within an HTML page. The HTML page would be cached, and it could then draw a PHP file containing your query results from the server into its iframe.
The server load would be determined by the elegance and scope of your queries, not necessarily by the number of queries. Are they exceedingly well-formed? Do they contain sub-queries? That kind of stuff.
Just thinking ...
But there are some easy ways to cache your output, if you do want to do that. There is at least one caching module in PEAR (see PHP site), and lots of add-on software. They all will require access to a webserver-writable directory to cache the files to.
If you can't or won't write to the filesystem on your shared server, you could pre-build the cache files in your development environment and upload them to the server. You'd probably only want to do that if updates are quite infrequent.
You got php/mysql driven pages but don't want to run the php/mysql queries every time but let a visitor see the 30minuten(or whatever) old version?
If that's the case simply write the php page to a html file. Like it does when a visitor visits your page.
And about the load. Don't worry about it unless it becoms a problem. Simple database queries are no load at all for a good server.
I did once load a double 3.0 xeon server to 47%.
But that was because of some miscoding:)
Goodluck
caching can mean 2 things
1) clientside caching - whereby you send headers (expires or last-modified) allowing the browser to cache the page instead of loading it again from your server. for instance to send last-modified headers correctly for a php/mysql page, you need to find the last modified times of all data which makes up the page and send the most recent.
i do this for one of my sites, and it means comparing up to 10 database tables, several templates and several included scripts and then sending the browser a last modified header. it is rather complicated, although once it is in place it works very well. clientside caching can save you bandwidth and is recommended by google [webmasterworld.com].
2) server-side caching. we use pear's Cache_Lite class which is easy to implement. this saves load on the database and greatly improves scalability. i would recommend it if you have good traffic.
if you want browser's to be able to cache your pages though, you still have to send last modified headers. (we use the internal cache_lite timestamp value and send it along with the cached data).
this site is an invaluable resource:
[web-caching.com...]
hope that helps (as you may imagine it's a subject dear to my heart ;-)