3
Is there any PHP function to find out if an IP address (meaning website) is in the air or not?
I found this function on the WEB but she did not satisfy me.... it takes too long to load.
function curl_info($url){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HEADER, 1);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 );
$content = curl_exec( $ch );
$info = curl_getinfo( $ch );
return $info;
}
$site = 'http://www.locaweb.com.br';
$info = curl_info( $site );
if( $info['http_code']==200 ) {
echo '<u>'.$site . '</u> - <strong>está no ar!!</strong><br />';
} else {
echo '<u>'.$site . '</u> - está fora do ar<br />';
}
What do you mean if an IP is online? Do you want to check what exactly? A service or user?
– KaduAmaral
From what I understand you want to check if a site is "online" right? If that’s the case I think this is really the best solution. It takes a long time? How long in seconds? Oh one more thing the site may be online but on the page be "in maintenance", I do not know if it is relevant, but it is the caveat.
– Jorge B.
worse than it takes rs, for example, testing 'https://www.google.com' this function takes 21 seconds to finish... I don’t know if I’m doing anything wrong, or if this is right
– MarceloBoni
The solution could be in Javascript?
– Caputo
could be yes, but I find it difficult to create such a solution
– MarceloBoni
Quick question: wouldn’t it be easier to use a service like Pingdom? (unless you actually want to develop a script for your purpose)
– Rodrigo Rigotti
no no, the purpose is another....
– MarceloBoni