Created
April 27, 2012 03:15
-
-
Save mebcomputers/2505377 to your computer and use it in GitHub Desktop.
php: check website is running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//returns true, if domain is availible, false if not | |
function isDomainAvailible($domain) | |
{ | |
//check, if a valid url is provided | |
if(!filter_var($domain, FILTER_VALIDATE_URL)) | |
{ | |
return false; | |
} | |
//initialize curl | |
$curlInit = curl_init($domain); | |
curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10); | |
curl_setopt($curlInit,CURLOPT_HEADER,true); | |
curl_setopt($curlInit,CURLOPT_NOBODY,true); | |
curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true); | |
//get answer | |
$response = curl_exec($curlInit); | |
curl_close($curlInit); | |
if ($response) return true; | |
return false; | |
} | |
if (isDomainAvailible('http://www.css-tricks.com')) | |
{ | |
echo "Up and running!"; | |
} | |
else | |
{ | |
echo "Woops, nothing found there."; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment