1

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

winfred adrah
  • 428
  • 6
  • 18
  • What is your question? – Filnor Oct 11 '17 at 10:25
  • @chade_ i have updated the question, i want the cron job or php file to check a URL every 15 minutes and send me an email if it does not find the file at the url specified. How do i do that? – winfred adrah Oct 11 '17 at 12:00

1 Answers1

0

Please follow this tutorial to add a cron jon in Cloudways with php

https://www.cloudways.com/blog/schedule-cron-jobs-in-php/

winfred adrah
  • 428
  • 6
  • 18