PDA

View Full Version : Redirect Incase of mySQL problem


Harley77
03-17-2005, 10:00 PM
If someone has posted something like this before, I couldn't find it.

What this does:
It will redirect visitors to a static webpage of your choosing incase a connection to the mySQL server could not be established.

Every so often, The SQL server of our host becomes unresponsive, usually only for a few minutes, but, it's still annoying to try and load the site and have it take forver then be finally be greeted with a lovely SQL error. So, now people can get a nice friendly error page instead.

Feel free to modify and mess with it however you choose.


UPDATED

Trigunflame has provided a more elegant, sitewide solution that effectivly does the same exact thing.


Installation:

1. open includes/db_mysql.php
2. find the code below in the connect() function


if (!$this->link_id)
{
$this->halt('Link-ID == false, connect failed');
return false;
}


3. Replace that with


// Redirect For SQL Server Down
if (!$this->link_id)
{
$url = 'http://narutotalk.org/';
header ("Location: $url");
}



Just replace the url with where ever you want it to goto.

I'm leaving the original file availible to download as it might be useful for other administrative purposes.

Polo
03-19-2005, 01:16 AM
I was looking for something like this... thanks for sharing ;)

Deaths
03-19-2005, 05:06 AM
Very nice, this is very usefull.

Tekton
03-19-2005, 05:09 AM
It doesn't take a good coder to make a great mod :)

Harley77
03-19-2005, 01:13 PM
Thank you very much.

One other note, if someone want's it, its not hard to modify the testcon.php file to take the database login settings from your vb config file. I just did it this way for flexibility and make it easier to test without causing site wide dissruption.

Deaths
03-19-2005, 02:16 PM
Thank you very much.

One other note, if someone want's it, its not hard to modify the testcon.php file to take the database login settings from your vb config file. I just did it this way for flexibility and make it easier to test without causing site wide dissruption.
I'm 99% sure this should so it, haven't tested though.

Trigunflame
03-20-2005, 02:54 AM
A better solution that will work on any page.

1. open includes/db_mysql.php
2. find the code below in the connect() function
if (!$this->link_id)
{
$this->halt('Link-ID == false, connect failed');
return false;
}

3. Replace that with
// Redirect For SQL Server Down
if (!$this->link_id)
{
$url = 'http://narutotalk.org/';
header ("Location: $url");
}


This will redirect users on any page, if the the DB connection could not be established.

All of the methods in the above posts's are redundant as they are trying to establish a "second" db connection. All that is going to do is slow down your pages on every load, and increase your mysql load by increasing its connections.

Harley77
03-21-2005, 12:36 PM
Ah ha! new there was a better way. Curious though, would this method redirect on any kind of SQL issue such as conneciton limit reached (server side, not though VB), or any other failure to connect to the server and not just on an outright connection failure?

Deaths
03-21-2005, 02:22 PM
My method, or his?

Harley77
03-21-2005, 02:38 PM
His, Just wasn't sure what all errors it covered. I know that the method I put up pretty much covered all the bases incase of any kind of issue, just wasn't sure if the same was true with Trigunflames.

Trigunflame
03-21-2005, 03:07 PM
His, Just wasn't sure what all errors it covered. I know that the method I put up pretty much covered all the bases incase of any kind of issue, just wasn't sure if the same was true with Trigunflames.

Well.. your covered just the index.php page, as well as deaths; which would be pointless if someone was browsing a forum/thread/post.
Not only that.. its issuing a second connection attempt, effectively doubling your total mysql connections...

The small lil mod I posted however, deals with it at the connection source inside of db_mysql. Thus every page, regardless if a connection cannot be established you are re-directed to the target location.

Modify your main post btw with the snippet I posted for peoples future reference.

Harley77
03-21-2005, 03:32 PM
Well.. your covered just the index.php page, as well as deaths; which would be pointless if someone was browsing a forum/thread/post.
Not only that.. its issuing a second connection attempt, effectively doubling your total mysql connections...

The small lil mod I posted however, deals with it at the connection source inside of db_mysql. Thus every page, regardless if a connection cannot be established you are re-directed to the target location.

Modify your main post btw with the snippet I posted for peoples future reference.

I understand where yours and mine covered in terms of forum location, I was just asking inso far as the diffrent types of sql failures, would yours cover them all. You seemed to answer that question in your post. Thanks. I'll update this post. I have a new idea now for this little script of mine, If it turns into something useful I'll post it. Thanks again.

Polo
03-23-2005, 03:12 PM
Thanks Trigunflame

/me udpates

halgrunwell
03-29-2005, 07:44 PM
Anyone every seen a variation of this that send a text message or email to you if the db is not connectable?

Polo
03-29-2005, 08:33 PM
Anyone every seen a variation of this that send a text message or email to you if the db is not connectable?
well I still get email messages telling me of the database error halgrunwell... I dont know if that relates to what you are talking about..

SaN-DeeP
03-31-2005, 01:26 PM
nice addon.. thanks

venomx
03-31-2005, 01:35 PM
This looks good but how will members know theres a problem if they auto get forwarded to a new site?

-=Sniper=-
04-03-2005, 10:47 PM
you can forward them to a page instead, saying the site will be back in a bit or something like that,

wirewolf
04-15-2005, 08:43 PM
This looks good but how will members know theres a problem if they auto get forwarded to a new site?Just make up a page for your site similar to this (I have a sister site (different host) that I redirect to in-case my forums' site goes down - either the sql database or the entire server):
Server Down Message (http://shipmodeling.info/serverdown.html)

Harley77
04-18-2005, 02:13 PM
I like mine :-)

http://www.demopolislive.com/sqldown.html