CodeIgniter Forums

Full Version: Making site offline
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I want to whole site go offline when the update script runs via corn job.
When the site is updating, should not accept any Mysql query&show;any pages.
Is there a easy way to do this in CI ?

El Forum

[eluser]Ty Bex[/eluser]

This is not a perfect solution but it will work.
This is only requre a local file read and no db connectivity.

1.) Create a file called "site_status.txt"
2.) The content of the file is a simple "1" for server up and "0" for server down.
3.) Write a library "l_stite_status.php" that opens and reads the value and sets a variable to 1 or 0 "var_site_status"
4.) Autoload the library
5.) In every class or at a higher level with a hook in codeigniter call the library and check if the value is a 1 or 0
6.) If there var_site_status equals 0 then redirect to a site is down for maintenance static html page.

Now just have your cron over write a 1 or 0 to the site_status.txt

El Forum

Well, it could easily be done using your database. As an example you create a table called "settings" with some different fields, one of the fields could be "site_status". Then you could code a model and check if "site_status" is "1" (online) or "2" (offline). Auto-load the model and check on every existing page. I don't know if anybody has an easier way to do it. Smile

El Forum

i am not sure if this would help or no but give it a try.

in your default application create a custom hook.

create either a "pre_controller" or a "post_controller_constructor"

this hook would go and check if an update is in progress. if so then kill the request and redirect to a "server is under update" page.

just remember that your cron job should reset whatever it is that tells the hook that update is in progress. it can be a temp file or a database record.