Web monitoring - check url

I need script to run from cron and monitoring my sites. Needed function is send me email when some error hapeened (timeout, service unavailable, not found,....). So I want to share my solution ;)


I would rather use some of the hosted services like Pingdom. However, if you really want to have it in house, take a look at Zabbix or Nagios.


I update script, now you can set:

  • array of emails to send warning (I recommend sms email for free sms warning)
  • email of warning sender
  • array of valid http status codes
  • minimum filesize (updated version check filesize too)

You can find working code here - http://pastebin.com/Cf9GyVJB

function checkURL($url) {

//array of emails to send warning
//email of sender
//array of valid http codes
//minimum filesize in bytes

if(!function_exists('curl_init')) die("Curl PHP package not installed!");

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

if(!in_array($statusCode,$validStatus) || $filesize<$minFileSize) {
    $message = "Web ERROR ($url) - Status Code: $statusCode, Filesize: $filesize\r\n";
    foreach($adminEmails as $email) {
        mail($email, "Web Monitoring ERROR", $message, "From: $senderEmail\r\nReply-To: $senderEmail\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\n");


Take a look at sparrow - http://blogs.perl.org/users/melezhik/2015/11/easy-nginx-monitoring-with-sparrow.html , this is a perl web test, monitoring framework could be easily used for any kinds of web applications. Sparrow consumes so called sparrow plugins - reusable tests suites, there are some already written, but you can easy create your own one. Full documentation could be found here - https://github.com/melezhik/sparrow.

Regards, the author of sparrow.

Need Your Help

Write a value with OPC UA Java (OPC Foundation)

java simulation opc scada opc-ua

I am trying to connect to a remote environment using the OPC UA java stack from the OPC Foundation. Reading values is working correct, for that I am using the following code: