PHP 计算出到达用户的最短路线(最快?)
是的,
基本上我需要计算出从服务器到最终用户的最短路径。 我有 2 个地理位置不同的服务器 - 一台在英国,一台在美国。
我需要根据最终用户的位置确定从哪个服务器加载内容。
我最初想到使用 fsock/curl/fgc 并发送带有用户 IP 地址的 $_GET 变量,然后(如果使用 Tracert)查看哪个输出具有最短的跳数,如果我要使用 ping,请参阅显然,最小的 ping 值。最后,将用户的 IP 地址存储在一个表中,并在下次加载网页时预先选择一个位置。
现在,随着我获得越来越多的服务器,这似乎非常不切实际,并且可能会导致许多痛苦的问题,
所以我向您提出的问题是:是否有更实用/简单的方法来完成此任务?
干杯!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
购买地理定位数据库订阅或使用网络服务,然后根据数据库/服务检查他们的 IP。将世界划分为多个区域,并决定哪个服务器应该为哪些区域提供服务。
根据您的查找在代码中决定根据内容的来源国家/地区从哪个服务器提供内容。
不要尝试使用网络跃点或实时跟踪路由来决定,这比简单地从单个服务器提供服务要慢得多。你想太多了。
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.
您可以使用用户 IP 来确定请求的来源国家/地区,并根据该信息分配 COLO。因此,美洲和亚洲访问美国网站,欧洲和非洲访问英国网站。可能需要一些测试来确保这是最合适的。 MaxMind 有一个免费的 GeoIP 数据集和软件:http://www.maxmind.com/app/geolitecountry
You could use the users IP to determine the country of origin for the request, and assign a colo based on that. So the Americas and Asia go to the US site, Europe and Africa go to the UK. Might need a little testing to make sure that was the most appropriate. MaxMind has a free GeoIP dataset and software: http://www.maxmind.com/app/geolitecountry