Reputation: 31
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...
Upvotes: 1
Views: 2069
Reputation: 382092
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).
Upvotes: 2