A few months ago, I wrote an article about how to implement an “under maintenance” plugin using Zend Framework plugins. This plugin allows you to easily redirect users of your website to an “under maintenance” in case of a planned downtime. Simply set a flag in your application.ini and that’s it. In this post we will extend this plugin.
A meaningful extension for this plugin would be to inform web crawlers & search engines that this downtime is temporary. Basically, all you have to do to inform Google, Bing and Co. about the status of your website is to set the correct HTTP status code. For our maintenance plugin, this would be 503 “Service Temporarily Unavailable”. According to W3C this status code is defined as: “The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.”
Furthermore, you can tell the web crawler when you expect your website to be up and running again by setting the ‘Retry-After’ status. In our example, we tell Google that it may retry crawling our website in 3600 seconds. Alternatively, you could also set a date, e.g. ”Sun, 22. Jan 2012 23:00:00 GMT”.
Both can be done in your maintenance Action by simply adding the following two lines of code
$this->getResponse()->setHttpResponseCode(503); $this->getResponse()->setHeader('Retry-After', '3600');
Hope this helps…