Right,
Basically I need to work out the shortest route from servers to the end user.
I have 2 geographically-placed servers – one in the UK and one in the USA.
I need to work out which server to load content from based on the end-user’s location.
I originally thought of using fsock/curl/fgc and send a $_GET variable with the user’s IP address and then either (if using tracert) see which output has the shortest amount of hops, and if I was going to use ping, see the smallest ping, obviously. This would all be topped-off with storing the user’s IP address in a table with a location pre-selected for the next time they load the webpage.
Now as I get more and more servers, this seems extremely impractical and could lead to many painful problems,
So my question to you is: Is there more a practical/simple way to complete this?
Cheers!
Buy a geolocation database subscription or use a web service, then check their ip against the database/service. Separate the world into regions, and decide which server should serve which regions.
Decide in code based on your lookup which server to serve the content from based on their country of origin.
Don’t try and use network hops or traceroute live to decide, that’ll be much slower than simply serving from a single server. You’re overthinking this.