Page 1 of 1

PHP :: check to see if a website is up or down

Posted: Thu Jul 11, 2013 6:01 am
by Stevyn

Code: Select all


<?php
// make sure site is up
//  more code at phuturecode.com
// uncomment to show errors
// error_reporting(-1);

// set the URL 
 $url="http://examplewebsite.com";
 
            
           $cl = curl_init($url);
           curl_setopt($cl,CURLOPT_CONNECTTIMEOUT, 2);
           curl_setopt($cl, CURLOPT_TIMEOUT, 3);
           curl_setopt($cl,CURLOPT_HEADER,true);
           curl_setopt($cl,CURLOPT_NOBODY,true);
           curl_setopt($cl,CURLOPT_RETURNTRANSFER,true);
 
           //get response
           $response = curl_exec($cl);
 
           curl_close($cl);
 
           if ($response) echo 'site up';
 
        else   echo 'site down';
 ?>