Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created February 28, 2011 23:49
Show Gist options
  • Save pifantastic/848299 to your computer and use it in GitHub Desktop.
Save pifantastic/848299 to your computer and use it in GitHub Desktop.
<?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