I have a woocommerce website hosted on cloudways, I want to monitor the website to know when it is down and when it isn't.
I have decided to use cron jobs with php to check for specific URLs on the website. I realised that cloudways has cron jobs set up in dashboard.
here is a sample of my code that checks if the image is available or not.
<?php
function is_webUrl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (curl_exec($ch) !== FALSE) {
return true;
} else {
return false;
}
}
if(is_webUrl('https://url/image.jpg')) {
echo 'yes i found it';
}else{
echo 'file not found';
}
?>
My question is, how do I use cron jobs to check for a file every 15 minutes and send me an email if the file cant be reached, but will do nothing if the file is found
Please follow this tutorial to add a cron jon in Cloudways with php