/    Sign up×
Community /Pin to ProfileBookmark

caching php dynamic output

Hello,

I use php to pull data from my database. I have alot of info that is pulled but does not change for hours and even days at a time. I would like to implement some type of caching so that everytime a page is loaded, I do not need to pull the data from the database. If you go to [url]www.middielight.com[/url], you can see that top downloaded, new files, requests and found are all pulled from the database. They do not change too often and I would like to cache the data.

I have read tutorials that cache the entire page but was a little confused. Also, if you go to the music categories, the artists that show up, stay fairly static and do not need to be dynamic either.

Anyone have a solution to make my site cached?

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@Stephen_PhilbinSep 06.2005 — Well if your database isn't that busy then there's probably no need if you're running MySQL. It caches the results of queries that are frequently run with the same results anyway. I'd say let the database do the caching so that if your content changes, people will get to see it.
Copy linkTweet thisAlerts:
@mididelightauthorSep 06.2005 — i am running mysql, i did not know that about the query caching. do you know the settings behind it? like what are the rules to cause a query to be cached?
Copy linkTweet thisAlerts:
@Stephen_PhilbinSep 06.2005 — It just remembers the results of the last few queries I think. Been a while since I read that bit of the manual. Why not download and have a read of the manual for yourself? It used to come with MySQL but now you can just download it seperately at mysql.com
Copy linkTweet thisAlerts:
@bokehSep 06.2005 — Why do you want to cache? Is it a speed issue or are you trying to save bandwidth?
Copy linkTweet thisAlerts:
@mididelightauthorSep 06.2005 — i am not sure if i am having a performance hit but I run 8 queries on my homepage alone and much of the dynamic content (besides recently requested) doesnt change. And since 8 queries run everytime someone hits the homepage, I figured maybe caching was a way to go. The homepage isnt too slow to load but I am not sure if 8 queries is too much for one page.

What do you think?
Copy linkTweet thisAlerts:
@bokehSep 06.2005 — Try this out: Put this right at the start of your script:
[code=php]$start = microtime();[/code] and this at the end:[code=php]$end = microtime();
print(elapsed_time_in_milliseconds($start, $end) . ' milliseconds');

function elapsed_time_in_milliseconds($start, $end){
$start = explode(' ', $start);
$start = $start[0] + $start[1];
$end = explode(' ', $end);
$end = $end[0] + $end[1];
return (round(($end - $start) * 1000));
}[/code]


Now run that and see if you think your script is slow.
Copy linkTweet thisAlerts:
@bokehSep 06.2005 — Also have you considered sending a 304 if the page is unchanged. This will save 100% of wasted bandwidth when people press refresh and the page has not changed but it does not save cpu cycles. Of course though by sending a 304 and no content to clients that have your pages cached.

If you want to try this out I have already written the code for this and would be happy to post it.
Copy linkTweet thisAlerts:
@mididelightauthorSep 06.2005 — ok so i tried your script and returned 120 miliseconds. Thats pretty quick. But since I have no basis for comparison, is that slow or fast?

www.mididelight.com/test.php

Also, I have not heard of a 304 page error, what is that?
Copy linkTweet thisAlerts:
@mididelightauthorSep 06.2005 — once i reset my cache in my browser it jumped up to 915 miliseconds.
Copy linkTweet thisAlerts:
@bokehSep 06.2005 — Well for me your page takes about 8 seconds to load the text so 120 milliseconds is not really worth considering. And regarding the cache reset that will not make any difference as the page is not cache. The proof of this is that the timer changes on every page load. Another problem you have is that your server is miss configured. My browser sends the header 'Connection: keep-alive' and your server responds with 'Connection: close'. This is very bad because it means the connection must be re-opened with each request. i.e. if you have your php page with 9 pictures on it the connection needsto be opened and closed 10 times instead of one and since opening the connection is one of the slowest things this is really slowing things down.
Copy linkTweet thisAlerts:
@daed17Sep 06.2005 — you can use eaccelerator to cache your pages. If you need any assistance let me know.
Copy linkTweet thisAlerts:
@mididelightauthorSep 06.2005 — bokeh - how do i fix this connection close problem? Is this something in my code or something I have to discuss with my host provider?
Copy linkTweet thisAlerts:
@bokehSep 06.2005 — It's nothing to do with PHP it's the server config so its down to whoever is in charge of the server.
×

Success!

Help @mididelight spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...