The Little Guy Posted January 26, 2012 Share Posted January 26, 2012 what would be the best way to test a websites up/downtime? I have a program that pings a website every 5 minutes, would that be a good way to test if the site is up or down, or would it be better to do a cURL request to the domain? OR... is there an even better way to test if a domain is up or down? Thanks! Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted January 26, 2012 Share Posted January 26, 2012 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. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 26, 2012 Author Share Posted January 26, 2012 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>"; } ?> Quote Link to comment Share on other sites More sharing options...
Philip Posted January 26, 2012 Share Posted January 26, 2012 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) Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 26, 2012 Author Share Posted January 26, 2012 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. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted January 26, 2012 Share Posted January 26, 2012 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 Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 27, 2012 Author Share Posted January 27, 2012 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? Quote Link to comment Share on other sites More sharing options...
scootstah Posted January 27, 2012 Share Posted January 27, 2012 There may be times a website doesn't run on port 80, so that wouldn't be 100% accurate. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted January 27, 2012 Share Posted January 27, 2012 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) Quote Link to comment Share on other sites More sharing options...
Adam Posted January 27, 2012 Share Posted January 27, 2012 .. Or if you really want to have a fun day, you can get into automated regression testing. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.