How to safely go to maintenance?

Hi,

I am wondering what would be the best way to take a yii website off the air for maintenance.

Anyone has experience with that?

I would like to have a simple page showing “we’re off the air, please, come back later”,

closing db connections, but ideally waiting for users that were browsing the site before the

maintenance page kicked in to finish their navigation as they might be in the middle of something.

Is there a right way of doing it?

Thanks in advance for any help!

Best

I would probably just replace /index.php to display what you want. You could create another virtual host to point to a different bootstrap file while you work on the application.

~thinkt4nk

You could do this:

http://www.yiiframework.com/forum/index.php?/topic/3975-maintenance-mode

Or use an extension:

https://github.com/karagodin/MaintenanceMode

That’s cool! I didn’t even know about ‘catchAllRequest’.

~thinkt4nk

I will probably use a solution that mixes both suggestions.

I’ll do the check for ‘.maintenance’ file in ‘index.php’:




<?php


require_once(dirname(__FILE__).'/../yii/framework/yii.php');

$config=file_exists(dirname(__FILE__).'/.maintenance')

	? include(dirname(__FILE__).'/protected/config/maintenance.php')

	: include(dirname(__FILE__).'/protected/config/main.php');

Yii::createWebApplication($config)->run();



And then ‘maintenance.php’ boils to:




<?php


return array(

	'catchAllRequest'=>array('site/maintenance'),

);



That way I can avoid any interaction with other components,

specially the database (I am using CDbHttpSession in ‘main.php’).

Thanks for the helpful comments!

What if I want to provide my client with the facility to put the site in online/offline mode from a backend setting?

Use PHP to create a .maintenance file - and likewise remove it.

For the best of both worlds: combine the extension with the tip. :)

The extension allows admins to login.

Any new ideas for this?