You can set up an alert to check for the presence of text on a web page. This can be used in its simplest form to check that the correct website is responding by checking that some text on the normal page is being served. Should the site or server encounter an error then the normal text will be replaced with an error page, or no page at all. When the monitoring server fails to find the normal test it will cause an alert.
Alternatively, you can create a server-side script to query a database, for example. The script could return a web page with either 'OK' or 'Query failed'.
The example below is for a web site running under PHP which checks that the connection to the database is functioning correctly.
<?php // If PHP can not connect to MySQL, the script will print "Connect failed" $dbh = @mysql_connect("127.0.0.1", "user", "password"); if (!$dbh) { die("Connect failed"); } // If a query of the 'users' table fails, the script will print "Query failed" if (!mysql_query($dbh, "select id from users limit 1")) { die("Query failed"); } // If everything is OK, the script prints "OK" echo "OK"; ?>
Last updated 28 August 2019, 08:13 GMT