Created
February 28, 2011 23:49
-
-
Save pifantastic/848299 to your computer and use it in GitHub Desktop.
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
<?php | |
function down_for_everyone($url) { | |
if (strpos($url, '://') === FALSE) { | |
$url = "http://$url"; | |
} | |
if (filter_var($url, FILTER_VALIDATE_URL)) { | |
$handle = curl_init($url); | |
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, TRUE); | |
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($handle, CURLOPT_MAXREDIRS, 30); | |
if (($response = curl_exec($handle)) !== FALSE) { | |
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE); | |
return "It's just you, $url is up and returned an HTTP status: $code"; | |
} | |
else { | |
return "It's not just you, $url is down."; | |
} | |
curl_close($handle); | |
} | |
else { | |
return "$url is like, totally malformed."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment