Fastest Way To Check If A Site Is Up??

Status
Not open for further replies.
You can try using

Code:
[COLOR=#000000][COLOR=#0000bb]<?php
$output [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000bb]shell_exec[/COLOR][COLOR=#007700]([/COLOR][COLOR=#dd0000]'ping www.test.com'[/COLOR][COLOR=#007700]);
echo [/COLOR][COLOR=#dd0000]"<pre>"[/COLOR][COLOR=#007700];
echo [/COLOR][COLOR=#0000bb]$output[/COLOR][COLOR=#007700];
[/COLOR][COLOR=#0000bb]?>
[/COLOR][/COLOR]


code was at http://www.phpfreaks.com/forums/index.php?topic=141972

But the chances of the server not having shell exec disabled is very high but if its not kudos to you :)


also look at

http://www.hotscripts.com/category/php/scripts-programs/networking-tools/ping/


 
The best way was mentioned earlier which was cURL the header. It's the fastest php way and most reliable not having to count on what settings other servers have. It's also a lot lighter on your server as your only getting part of the page. file_get_contents get's the whole page and is slow and fopen is even slower. Their is a command exists() that you can use to check if a file exists but I think this only works if your checking a file on your own server.

EDIT: and ya I think it's a good idea to check if a site is up first. It will be slightly faster if you check it's up before trying to submit to a dead site. Nice idea.
 
Using this method:
Code:
$head = get_headers("http://www.google.com", 1);
if(strpos($head[0], "200") !== false){
echo "Website OK";
}else{
echo "Website DOWN";}

...seems toi be very fast at telling if the website is up, BUYT if its down it just loads for ages then kicks out this error:
Code:
php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution

Code:
failed to open stream: Permission denied

PS: i have missed paths/line numbers out of the errors.
 
Status
Not open for further replies.
Back
Top