16
Apr
Create a PHP CLI script called monitor.php like this
- #!/usr/bin/php -q
- <?php
- define ( “ TIMEOUT “ , 30 ) ;
- define ( “ EMAIL “ , ‘ abc @ youremail . com ‘ ) ;
- check ( “ http://hosta.com “ ) ;
- check ( “ http://hostb.com “ ) ;
- check ( “ http://hostc.com “ ) ;
- check ( “ http://hostd.com “ ) ;
- function check ( $url ){
- $ch = curl_init () ;
- curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ) ; // Return Page contents.
- curl_setopt ( $ch , CURLOPT_URL , $url ) ;
- curl_setopt ( $ch , CURLOPT_TIMEOUT , 30 ) ;
- curl_setopt ( $ch , CURLOPT_DNS_CACHE_TIMEOUT , TIMEOUT ) ;
- curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , TIMEOUT ) ;
- curl_setopt ( $ch , CURLOPT_HEADER , TIMEOUT ) ;
- $result = curl_exec ( $ch ) ;
- curl_close ( $ch ) ;
- // HTTP/1.1 200 OK”)
- if ( strpos ( $result , “ 200 OK “ ) != 8 ){
- mail ( EMAIL , “ Error in $url “ , $results ) ;
- }
- }
- ?>
Add this line in your Linux /etc/crontab or via cpanel to monitor eg: every 3 minutes
*/3 * * * * root /usr/sbin/monitor.php >> /dev/null 2>&1




