Fastest Way To Check If A Site Is Up??

Status
Not open for further replies.

DEViANCE

Active Member
1,399
2009
64
0
Hi, I have been playing around with an old auto submitter script.

I added a function to see if the sites in the list are online before submission, so they would be automatically unticked if they were not online:

10p4mlt.jpg


This is the function i used:
Code:
function Visit($url)

{

$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init();

curl_setopt ($ch, CURLOPT_URL,$url );

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch,CURLOPT_VERBOSE,false);

curl_setopt($ch, CURLOPT_TIMEOUT, 5);

$page=curl_exec($ch);

//echo curl_error($ch);

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if($httpcode>=200 && $httpcode<300) return true;

else return false;

}

But it takes a very long time to load even with just ten or so sites using this method.. Is there any faster way to do this???
 
28 comments
Probably takes a while because codemafia.org needs to timeout? Not sure you can make it any quicker at run time unless you set up a seperate task to check the sites every few minutes and store in a database then load that into the page?
 
Nope, i only put codemafia.org in thier as an example for my screen shot, even when all sites are up its taking at least like five seconds or maybe ten... pages should not take that long to load nomatter what your doing..??

The only thing i can think of (as im pretty sure this is one of the best methods) is learning AJAX so i can make the sites show up as they are resolved?? I am ok with php but not tried ajax yet so might take me awhile to understand it.

I really need a faster function, even if its just slightly faster... :)
 
Assuming the host will respond to pings...

Maybe get_headers() - look for the 200 header - or file_get_contents() - look for something specific on the page; might be faster...
 
Can you give me an example of the get headers method? I don't think file get contents is good at all, will surely take loads longer...??
 
If a host has disabled pings that will cause a variety amounts of issues to the server

97.99+ % ping is never disabled and if need be just make a .bat script to ping it
 
PHP:
$head = get_headers("the url you want to check", 1);
$head is then an array, for example:
Code:
Array
(
    [0] => HTTP/1.1 200 OK
    [Date] => Sat, 29 May 2004 12:28:14 GMT
    [Server] => Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
    [ETag] => "3f80f-1b6-3e1cb03b"
    [Accept-Ranges] => bytes
    [Content-Length] => 438
    [Connection] => close
    [Content-Type] => text/html
)
You could then check it in many different ways...
PHP:
if(strpos($head[0], "200") !== false){
    // site is up
}else{
etc...
Reason I did that rather than simple == check is because they won't always have the same response. Maybe HTTP1.0 instead etc...
 
@william
I don't care about this ping thing unlerss you can provide a code example, sorry to be blunt but i want to get to the bottom of this and move forward, if you can't give me a code example your not good enough at php to help me in this thread.

Thanks bennelsworth, i will look into this. :)

Equal to or greater than 200 and less than 300 should work.
 
Hehehehe its ok im not much of a fan at php

but here is a .bat script

Code:
@ping wareztech.com > nul
@IF ERRORLEVEL 1 GOTO dead
@IF ERRORLEVEL 0 GOTO alive

:dead
@net send wareztech.com Dead
@ECHO Dead
@GOTO end

:alive
@net send wareztech.com Alive
@ECHO Alive
@GOTO end

:end

@ECHO Bye
 
Why would you even want to run a .php script to check if a site is up? not judging your creation as i think its unique idea actually.


If you want ill create a software that will do this are you wanting to ping a certain amounts of domain names or unlimited?
 
Shared hosting, about 45 sites on server.

The reason why i want to do it is cos there is no point submitting to dead/down sites (which makes the process almost as long as this atm), so it unticks them... maybe a bad idea in practice but i like the actual idea and if i can get it to work at a decent speed i will keep it, else i won't.

I am just brain storming, i don't even have a template for it yet.
 
Are you the owner of this server? if so why not just create a .pl script which pings the whole network of sites and informs them if there site is down ?

sounds a lot easier but yeah that is a good idea now that you said that i can see where your coming from
 
No i do not own the server, and i work with php, its a php ddl submitter sacript i am making......

Anyway for now i have made it so as default it does NOT check the sites but i make a link like site.com?check=1 and then it will check if they so desire... :)

I just hope i can find a better method or its a waste of a good idea.
 
Hmm im not advanced at php but just using a thought you can do this

make a db in your server make a script to connect to the store in the db all the sites that create a account on your site there site gets stored in the db after that make a script that will do a scan every 7 minutes or higher by doing a get request from the domain name they added to your site if your script recieves the get request on port 80 then its up if not its down which will then show a image or a text that you specify
 
Status
Not open for further replies.
Back
Top