Adding far future dates dynamically to any output in Seagull

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:
  1. $expires = 60*60*24*14;
  2. $output->addHeader("Pragma: public");
  3. $output->addHeader("Cache-Control: maxage=".$expires);
  4. $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

This post was written by Shaun on March 18, 2010

Tags: , , , , ,

Changes to ad creation form on sellstuff.co.za

I have made further changes to the ad creation form on www.sellstuff.co.za, so now if you try and create an ad and it fails on the PHP validation, your form will redisplay with the values you entered in, which is nice.

Also when your ad is created successfully your newly created ad is displayed, which it should have done, but I had a bit of a bug in my code :(

Added to that I now check for email addresses in the ad fields in PHP as well, you see some people just don't listen when you ask nicely, then everyone is impacted.

Lastly I moved things around on the form a bit so that the first thing you see on the form is the actual form and not all the warnings that I will de-activate your ads and account etc. I think this looks better.

Posted under Classifeds Sites Updates

This post was written by Shaun on March 17, 2010

Tags: ,

Error fixed on ad creation page – www. sellstuff.co.za

If you tried to create ad ad on www.sellstuff.co.za recently you may have had a bit of trouble getting it done.

I have, for quite some time spent a large part of each day removing suspicious looking ads, as well as ads that do not fall within the guidelines for www.sellstuff.co.za.

I also added text to the ad submission page specifically requesting that people do not ad their email addresses in the description field, but many people seemed to have ignored this completely, so I did something about it.

Last week (I think) I added extra validation to check that no email addresses had been added in any of the fields on the ad submission form, then tested it and it worked....... problem is I tested it when I was logged in.

You see the same form gets used whether you are logged in or not, and when you have not registered, or logged in there are additional fields for your username, and ... email address. So my validation worked so well when you filled your email address in the email address field, it told you no email addresses are allowed, not nice :( , remove your email address from that field and you cannot submit the form really really not nice.

Thankfully a user took the time to send me a mail letting me know about the problem, which is now fixed.

So in closing, if you have any issues at all on the site, let me know! I won't ignore you. Thanks to all those people who have sent me feedback it is appreciated!

Posted under Classifeds Sites Updates

This post was written by Shaun on March 10, 2010

Tags: , , ,