Posts Tagged ‘HTTP’
16
Apr

Create a PHP CLI script called monitor.php like this

  1. #!/usr/bin/php -q
  2. <?php
  3. define ( TIMEOUT , 30 ) ;
  4. define ( EMAIL , ‘ abc @ youremail . com ) ;
  5. check ( http://hosta.com ) ;
  6. check ( http://hostb.com ) ;
  7. check ( http://hostc.com ) ;
  8. check ( http://hostd.com ) ;
  9. function check ( $url ){
  10. $ch = curl_init () ;
  11. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ) ; // Return Page contents.
  12. curl_setopt ( $ch , CURLOPT_URL , $url ) ;
  13. curl_setopt ( $ch , CURLOPT_TIMEOUT , 30 ) ;
  14. curl_setopt ( $ch , CURLOPT_DNS_CACHE_TIMEOUT , TIMEOUT ) ;
  15. curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT , TIMEOUT ) ;
  16. curl_setopt ( $ch , CURLOPT_HEADER , TIMEOUT ) ;
  17. $result = curl_exec ( $ch ) ;
  18. curl_close ( $ch ) ;
  19. // HTTP/1.1 200 OK”)
  20. if ( strpos ( $result , 200 OK ) != 8 ){
  21. mail ( EMAIL , Error in $url , $results ) ;
  22. }
  23. }
  24. ?>

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

, , , ,