PHP MySQL - check if remote website is up and MySQL is running
Posted on 2005-05-05
I have a website that displays ads - website A.
The ads are located on a MySQL database, which is located on a remote website B that I connect to via my connection script below.
Contents of conn_data.php
$hostip = "18.104.22.1686";
$hostname_conn_data = $hostip;
$database_conn_data = "ads_data";
$username_conn_data = "ads_user";
$password_conn_data = "ads12345";
$link = $conn_data = @mysql_pconnect($hostname_conn_data, $username_conn_data, $password_conn_data);
I would like to run a script on website A via cron say every 5 mins that will not only ping website B but also check if MySQL is running with no problems.
If it finds a problem with either the website not being available or MySQL being down then I need this script to be able to set a flag as down and also change the value of $hostip in my conn_data.php connection script to point to my backup server.
The next time the script runs it will check if the flag is down and if Website B is back, then reset IP address back to normal & flag to up, if its still down do nothing.
I guess the flag would just be a text file, which will contain the word UP or DOWN depending on the status of website B.
I would also have a sms message sent to my cell (mobile phone) when Website B is down and also when it comes back up.
I already have set up and tested my sms script supplied by sms gateway to handle the sms message, I just need the script for the above to trigger this.
Any comments or feedback would be appreciated.