Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate a 'down' website?

I am writing some failover code so that if my desktop app cannot connect to its website, it can instead try a backup website.

However, I cannot seem to figure out how to simulate a test if a website is 'down' or not. If I try an obvoiusly incorrect url such as "http://www.mybadsite.badTLD" , my ISP provider sends me to a default catch page.

Whereas when a site is truly down and you cannot connect to it, you get the browser message saying it cannot connect. This is what I need to emulate.

Thanks

like image 426
mikew Avatar asked Mar 31 '11 20:03

mikew


3 Answers

Edit your hosts file to redefine the host you're trying to connect to. You can do 127.0.0.2 (Or anything unreachable).

You can also do a test with 0.0.0.0 - that returns a different error (Invalid IP). There may be some benefit to testing for that too.

Your ISP is redirecting for a DNS lookup failure, but anything resolved by your hosts file short-circuits that.

like image 91
Lee Kowalkowski Avatar answered Oct 20 '22 08:10

Lee Kowalkowski


In order to test how your scripts deal with different responses I'd rather use a special server that generates different HTTP codes. One of them is httpstat.us

In your case, the correct http status code is 503 (Service Unavailable).

The 503 status code indicates that the server is currently unable to handle the request due to a temporary overload or scheduled maintenance

which will likely be alleviated after some delay.

For more information on http status codes I suggest reading This IETS Documentation

like image 26
PinguinoNero Avatar answered Oct 20 '22 10:10

PinguinoNero


http://localhost

Assuming you do not have a server running locally...

like image 41
Dave Rager Avatar answered Oct 20 '22 09:10

Dave Rager