Jump to content

Test Website Up/Down


The Little Guy

Recommended Posts

Ping only tells you if there's a working OS at the other end of the line.

 

cURL only tells you if the web server is serving SOMETHING, not necessarily the page itself.

 

You need to combine curl with grep (or preg or whatever) and ensure that the page CONTENTS are coming through.  If I wanted to check if PHPF were up, I would check for the phrase "Page Created In" because that only shows up in the footer and only on successful page load.

Link to comment
Share on other sites

I don't think you need to do regexp, I'm sure this would work:

 

<?php
$domains = array("http://asdfasdfaassafaf.com", "http://google.com", "123.123.123.123");
foreach($domains as $domain){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $domain);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if($info['http_code'] == 0)
	echo "Page not served from $domain";
else
	echo "$domain Responded: ".$info['http_code'];
echo "<br>";
}
?>

Link to comment
Share on other sites

That could return a 403, 404, 500, etc. return code which means your user doesn't have access to the page. That could be because of the page IS a 404 page or whatever, but it could also mean that you have an error with the server setup.

 

At the least, you should be checking a normal page (non-404 nor authorization required) for a HTTP 200 code. Dan's solution is more robust in making sure your page actually outputs something worthwhile (although if you have dynamic pages you'd have to select something more general like <html)

Link to comment
Share on other sites

That could return a 403, 404, 500, etc. return code which means your user doesn't have access to the page. That could be because of the page IS a 404 page or whatever, but it could also mean that you have an error with the server setup.

 

At the least, you should be checking a normal page (non-404 nor authorization required) for a HTTP 200 code. Dan's solution is more robust in making sure your page actually outputs something worthwhile (although if you have dynamic pages you'd have to select something more general like <html)

 

But the web service still responded, which is all I am really after. I don't really care if a page works or not, but whether or not the web service is working.

Link to comment
Share on other sites

But if the web service returns a 503 with every request, is that "working?"  That's the question.  What constitutes a "working" website? 

 

If you just want to know if the server is turned on, use ping.

 

If you just want to know if apache is running, use curl with no check.

 

If you just want to know if PHP is working, use curl with preg to pull specific items off a known good page.

 

If you just want to know if the whole end-to-end website is working, perform activity on the site (creating content, changing menu options) and check their results with multiple sequential calls from cURL or some other page-fetching tech.

 

-Dan

Link to comment
Share on other sites

For the service I am providing, I think what I posted would be fine. As I am not providing a service to check if you page renders correctly, but if it responds to requests that come into the server.

 

But I still don't know, but.. I do believe that sending a cURL request to the server is the best way to check if a website is up/down, and sending pings to test if a server is up/down. Is there a better way to check, maybe something like http://canyouseeme.org and test port 80?

Link to comment
Share on other sites

There isn't much more to say to this, I already gave the whole list.  If you don't think "is port 80 responding" is enough of an indication of "up," then...go down the list.

 

When I wrote the monitoring for softlayer, those were the levels we offered: Ping, tcp connection, tcp response, parsed string response.  (plus a lot more for non-web servers, but that's the web stack)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.