Using statuscake.com to monitor your website and database uptime
Note: Updates have been added since this article was originally written. These updates are listed at the bottom of this page, click here to view them.
Once you have setup an account, you will be able to start adding monitoring checks. By using the code within this repository, you will also be able to setup your check to monitor your website’s database.
Monitoring a database is extremely important. It is vital to ensure connections can be established without any issues – otherwise your website can not be used by a visitor.
Firstly, you will need to download a copy of the repository from Github here: https://github.com/ryanfitton/website-check-monitor.
Open the file named ‘website-check-monitor.php’, ensure you change the database connection values to match the same values as your website, you can then upload this file to a publicly accessible place on your website – preferably to a password protected folder using .htaccess and .htpasswd.
The code works by sending a 404 (Not Found) error response if the page cannot establish a database connection, this tricks Status Cake into thinking the website is down. Otherwise if the connection is successful; a 200 (OK) response code is sent.
Once the file and password protected folder has been setup on your web server, you can then setup the monitoring check within Status Cake.
By using the example screenshot below, you will want to ensure you have similar settings.
Save your Status Cake check, your check should now notify you when your website or database is unavailable.
Download from Github here.
Updates (Version 1.1 – 18/10/2016):
- The ‘website-check-monitor.php’ code has been updated to check if the built-in PHP function ‘http_response_code‘ exists. If it does not, it’s likely the server is running a PHP version older than 5.4.0. In this instance, a custom function will be used which does the same job.
- This code has also been tested to work with PHP Server Monitor, an open-source self hosted solution.
- If the website’website-check-monitor.php’ file is protected with .htaccess/.htpasswd, some monitoring services may not allow you to enter a Username and Password to authenticate. In this case, you should change the URL which points to ‘website-check-monitor.php’ in your monitoring service to: ‘https://yourusername:email@example.com/website-check-monitor/website-check-monitor.php’ – (Replacing the relevant details).
The license for this software is Creative Commons: Attribution 4.0 International.
This means you can Share and Redistribute in any medium or form. You can Adapt the code to suit your needs, and build in new code. The software can be used personally or commercially.
You must give attribution to the original author (Ryan Fitton). You can give attribution by including my name and linking to my website: https://ryanfitton.co.uk within the top of the monitoring PHP code.
Website Check Monitor script Plugin by Ryan Fitton is licensed under a Creative Commons Attribution 4.0 International License.