Turning app offline/online on demand.

Hello, we are developing a browser game with Flash (front-end) and Yii 1.1.16 (Back-end). The game server is a yii web-app that receives requests from the client for the game to progress. Our intent is to have at some point multiple servers.

What I want to do: From a central admin panel that we have built I want to be able to set a game server (yii web app) offline with a press of a button and then turn it on.

I have thought of two ways of doing this, one seems more logical from the other, but I want your opinion.

  1. The first method is to store in the database a boolean field (isOnline) and read it with a select before each action. If it is false I will render the appropriate view informing the requester of the server being offline. The lead programmer is not so fond of this idea because he doesn’t want to have one extra query to the database for every request.

  2. So because of the "problem" above I came up with a different solution that does not use the database. So here it is:

In config/main.php I add this to params:


    'isOnline' => require(dirname(__FILE__).'/online.php'),



the config/online.php file is just this:


//param that decides if server is online or not

return false;

And in Controller beforeAction I have this:

//If server is offline

if(!Yii::app()->params['isOnline'] )


    //allow only 'switch' action

    if(Yii::app()->controller->id.'/'.Yii::app()->controller->action->id == 'test/switch')


        return true;


    //else diplay offline view




In order to change the online status (the action needs improvement, it just works for now):

public function actionSwitch ()


    //Get online input, TODO add input checks

    $isOnline = $_GET['online'];


    //Create online.php file contents, using a simple view with an echo inside

    $fileContent = $this->renderPartial('//site/online', array('online' => $isOnline), true);


    //Open config/online.php file

    $file = fopen(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'online.php', 'w');


    //Write new content to file

    fwrite($file, $fileContent);


    //Close file



Personally I prefer the first approach and I have doubts about the security of the second approach. What are your opinions (generally and then taking into consideration my colleagues disaproval of the db solution)? Any other approach?

Thanks a lot in advantange.

Answering my own question thanks to a comment in StackOverflow. Db approach is the way I decided to go, and in order to eliminate the extra request to the db in each action, I decided to cache the result and update it on change.