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

Let us talk about scripts, HTML, Perl, PHP, apache, etc.

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

Postby Stevyn » Wed Jul 10, 2013 3:01 pm

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';
 ?>

Contact me directly: Ironfeatherbooks (@) gmail.com

Image
User avatar
Stevyn
SysOp
 
Posts: 1565
Joined: Sun Nov 08, 2009 7:03 pm
Location: Colorado

Return to WEBMASTER CHAT



Who is online

Users browsing this forum: No registered users and 2 guests

cron