PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, May 19, 2022

[FIXED] How can I simulate a 'down' website?

 May 19, 2022     http, httpwebrequest, web-applications, web-services     No comments   

Issue

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


Solution

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.



Answered By - Lee Kowalkowski
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing