Code Igniter out of service page »
FERDY CHRISTANT - NOV 19, 2008 (08:17:13 PM)
When you're building a large global web application (like I'm doing with Project JungleDragon) it makes sense to think ahead. For one reason or another, your application may have to be taken down (for example for maintenance or a migration). In those cases, you at the very least want to present the user with a friendly "out of service" page. This page should be displayed for every incoming request, the content of the page should be flexible, and it should be really easy for a web master to place the page.
Luckily, this is extremely easy to solve in Code Igniter due to it's Front Controller pattern. All incoming requests pass by the Front Controller script (index.php) anyway, so all we have to do is alter it somewhat:
1: $service_file = APPPATH . 'views/admin/noservice.html';
2: if (file_exists($service_file))
5: require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
This patch simply checks if there is a noservice.html file and if so, it loads it. If it does not exist, the application will work as usual. Whilst I could have implemented this more elegantly in a configuration setting or database field, I prefer this approach. In the case of a service take down, no code needs to be touched and there is no dependency on a database (which may be part of the maintenance, the very reason the service is down). Plus, it is extremely easy for the administrator to publish and remove the take down notice.
Another thing to think about are smart 404 pages. 404 pages in dynamic sites may appear for various reasons: an error in the application, an outdated bookmark of a user, other site or search engine, data archiving or migration, etc. This article explains how these reasons can actually be detected, so that the user is elegantly helped, whilst the web master knows what to fix.
Although these tips are simple, I'm convinced they make your application all the more robust and user friendly.