This post explains about website monitoring. My friend Vidhi made simple script to get the your website uptime. Using this script we will get information about your websites. If we have more number of websites then it is an awesome tool to monitor your websites.

Website uptime monitoring using php script by Anil Labs

Website uptime monitoring using php script by Anil Labs

We have the basic need to check weather the our website is working fine.Sometimes due to issues by the Hosting servers,Website goes DOWN. At that moment owner should aware of that the Website goes DOWN so that Owner can take the right action at the moment OR he/she can direct contact to the Hosting server company.

But for that we need to check the website status every time.So We can run such script at given period of time (ie. 5 Minutes,10 Minutes) and It checks the website status every time.It will mail the owner if it founds that Site is DOWN.We can set the script using our cron job with decided period.

Tip : If you want to create such script then use the CSV method shown in demo.Follow the below steps :

1)You can create the thousands of entries of your website with their admin email id in your CSV file.

2)Create the cron job with every 5 Minutes and set the attached script.

3)Rename the CSV file in script with your CSV file.

4)Status messages of all your websites which are provided in CSV file will get mail using one of below links


How to add HTML content in php mail() function
Sending mail using phpmailer and gmail as smtp
How to send mail using phpmailer class

Rest will taken care by the script.Admin will notify as soon as the Site will goes DOWN.

Sample code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function url_status($url) {
    $handle = curl_init($url);
   
    curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE)
       
    curl_setopt($handle, CURLOPT_TIMEOUT, 10);

    $response = curl_exec($handle);
       
    $httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
       
    curl_close($resource)

    return $httpCode == 200; // 200 =  STASUS OKIE
}

Subscriber users will get complete code.


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *