HTTP Status Endpoint for UptimeKuma for PHP websites like WordPress


So after I saw TechnoTim’s latest video showcasing a project called Uptime Kuma, he shows how to setup and use Uptime Kuma for monitoring websites and network services running under TCP. One of the problems with monitoring a website, such as one powered with WordPress, if you don’t use decent caching, the uptime check can put a bit of a load on your server, and it will have a longer response time.

There’s two obvious answers. Setup and use caching or make a dedicated status endpoint for your website. This post looks at the second option, which will also work if you’re developing a website as you don’t want to use a cache while you’re still working on things, yet don’t want to cause unnecessary load on your server for a simple uptime check.

I wrote a simple PHP script for the task

header('Content-Type: application/json');
$check_key = $_GET['key'];
if ($check_key == "SEKRET") { 
$http_status_code = http_response_code();
$current_time = date("c");
$response["success"] = true;
$response["http-status-code"] = $http_status_code;
$response["server-time"] = $current_time;
} else {
$response["success"] = false;
$response["authentication"] = "failed";
echo json_encode($response);

You can add this to your server, and even set a secret key in case you don’t want other people to be able to access it. You would access it with status.php?key=SEKRET (in the case of my example). If like me, you’d like to make the URLs a bit prettier, you can use htaccess to setup a rewrite rule to hide the php file extension.

RewriteRule ^status$ /status.php?key=none [QSA,L]
RewriteRule ^status/([0-9a-zA-Z-]*) /status.php?key=$1 [QSA,L]

You need to add this somewhere in the rewrite section of your .htaccess file, somewhere near the top.

Then you can add the URL to Uptime Kuma, such as (if you haven’t changed your key!) with a keyword, and search for “success”:true

Happy uptime! 🙂

Leave a Reply

Your email address will not be published.

Solve to post *