I have been trying to optimise www.picturearchive.co.za as the database is growing substantially daily, and I want it to have as little impact on the server as possible for future when the database is even bigger.
Using the YSlow firefox addon I noticed that they recommended adding expires headers to the page and the pages elements, this makes the elements cacheable and makes the page appear faster the next time the user visits it.
So after numerous attempts at adding expires headers in to Seagull I sent asked for help on the mailing list. The reply was that there is built in functionality so that you can add php headers on the fly, very nearly anywhere in Seagull!
So I know that the usenet postings are saved to database and never changed after that, so I can add expires headers that are far into the future, so if a user visits the same page 3,4,5 days in a row, he will always pull his locally cached page, saving them time, and having less of an impact on the server.
Below is the code that I implemented in the method that prepares the data to display the usenet article.
PHP:
-
$expires = 60*60*24*14;
-
$output->addHeader("Pragma: public");
-
$output->addHeader("Cache-Control: maxage=".$expires);
-
$output->
addHeader('Expires: ' .
gmdate('D, d M Y H:i:s',
time()+
$expires) .
' GMT');
On the first line we get the number of seconds in 2 weeks (60 seconds X 60 minutes X 24 hours in day X 14 days)
then set the headers accordingly.
I used the Live HTTP headers add on in firefox to see exactly what the headers were that were being sent from the server, that way I could see my changes take affect, brilliant!
I got the headers and the calculation from a users comments on http://php.net/manual/en/function.header.php
I did something similar for the pages that list the thumbnails for the usenet groups, but changed it to cache for a day only, as these pages will change, quite likely daily.
And there you go! 4 lines shoved into you manager in Seagull and you are forcing the browser to cache your pages.
I think that's a job well done, let the framework do the legwork and the developer concentrate on development!
Posted under Seagull PHP Framework