Skip to content

Instantly share code, notes, and snippets.

@angelbladex
Last active October 12, 2015 20:00
Show Gist options
  • Save angelbladex/61cfb66c3023132c4d20 to your computer and use it in GitHub Desktop.
Save angelbladex/61cfb66c3023132c4d20 to your computer and use it in GitHub Desktop.
some code on PHP for test access to websites with curl
<?php
function nxs_cURLTest($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
$response = curl_exec($ch);
$errmsg = curl_error($ch);
$cInfo = curl_getinfo($ch);
curl_close($ch);
echo "Testing ... " . $url . " - " . $cInfo['url'] . "<br />";
$httpcode = $cInfo["http_code"];
echo "Http Code " . $httpcode;
if ($httpcode >= 200 && $httpcode < 400)
echo "....<b style='color:green;'> - Ok</b><br />";
else
{
echo "....<b style='color:red;'> - Problem</b><br />";
echo "Curl error: " . print_r($errmsg);
echo "<br />";
//print_r($cInfo);
//echo "<br />";
//print_r(htmlentities($response));
echo "There is a problem with cURL. You need to contact your server admin or hosting provider.<br />";
}
echo "------<br />";
$response = null;
$errmsg = null;
$cInfo = null;
}
$sites = array(
"http://www.unet.edu.ve/",
"https://www.google.com/intl/en/contact/",
"http://www.cgr.gob.ve/",
"https://www.facebook.com/",
"https://www.pinterest.com/",
"http://www.yahoo.co.jp/",
"https://mobile.twitter.com/",
//"http://unal.edu.co/",
"http://www.cinemateca.gob.ve/fcn/index.php/en/",
"http://www.ciudadccs.info/?s=especulador+Precoz",
"https://tumblr.com/"
);
foreach ($sites as $site)
{
nxs_cURLTest($site);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment