1

I have a php code that checks if an url is live or not.

while(urls exist) {
check(each url);
}

Let's say that you input a list of urls on a form to check them, when I procced with the checker (using curl and a while loop) what the code does is check all of them one by one and then display all the result data at the same time. So if there are too many urls it takes a lot of time loading without showing results, and then BUM, all the results!!

What I want is implement jQuery or something to check the first url and inmediatly display result, then the next url and so on. Like this:

    Checking (2 of 200)
    Live!
    Live!
    Checking...

Can anyone help me with this or link to a tutorial, I couldn't find anything related, just how to submit forms with jQuery Ajax... Thanks!

Extra question: Any way to make this multithreading like:

Live!
Live!
Checking...
Checking...
Checking...
QuiGloriam
  • 31
  • 3
  • you can do a ajax call where you send the site or the index, and return the status. – Alexandru Chelariu Nov 29 '12 at 12:16
  • you should probably post you curl code too since it seems as if your downloading the content to see if a site is aliev, which isnt necessary you could just check the headers, http://stackoverflow.com/questions/4607684/curl-and-ping-how-to-check-whether-a-website-is-either-up-or-down here is a good example of that – Breezer Nov 29 '12 at 12:19
  • Do you want to do it from the browser or from the server (in this case I'll remove my answer but it would have nothing to do with ajax). – Denys Séguret Nov 29 '12 at 12:21
  • I want to do it from server side, I was thinking on make a jquery ajax post to checker.php?url=each url for each url – QuiGloriam Nov 29 '12 at 13:02

1 Answers1

2

If you want to check a server is available from the browser, the best is to make HEAD requests (no content downloaded) :

$.ajax({
    type: "HEAD",
    url: 'https://www.google.com',
    success : function() {
       alert('my server is alive !');
    }, error: function() {
        alert('world is gone !');
    }
});

Of course, as those requests are asynchronous, they'll be automatically parallelized (the exact number of really parallel request is browser dependant).

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • Not if the CORS header isn't set to allow it. – Denys Séguret Nov 29 '12 at 12:20
  • Getting error in console Mixed Content: The page at 'My current website' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://www.google.com/'. This request has been blocked; the content must be served over HTTPS. – Hassan Khan Jul 12 '22 at 12:32
  • @HassanKhan Change the URL in this answer from `http://www.google.com` to `https://www.google.com`. Or better: put the URL you want to test. – Denys Séguret Jul 13 '22 at 15:14