Reputation: 3711
I have a website that in a few months is going to have traffic from different countries, but it would depend on the country which website I should show.
At the moment I am redirecting the traffic using the free maxmind GeoIp, with php.
But I think that with 40k unique users a day, and arround 100k request a day this is going to be really slow.
I thought about doing this with .htaccess but I think the request time is going to take a little bit more.
My final idea now was to build the home in html of the site in different folders (or subdomain) according to the country, like us.website.com and redirect the users to there, but I do not know which of the way is the fastest for the user experience.
Server is LAMP (I can choose the distro)
Please help me decide!! Thanks for everything!
Upvotes: 3
Views: 767
Reputation: 12624
A downloaded MaxMind GeoIP Country database (free or payed, makes no difference) is quite fast when accessed from PHP (even if their PHP code is not optimized - it is quite clearly badly translated from good C code).
Just time it on your machines (e.g., by the difference of two calls to microtime(true)
with a realistic dataset), and you'll probably discover that you can afford accessing the GeoIP DB at the top of your code, in order to switch to country-specific code where needed.
The next step is using a country-code cookie. If the user already has the cookie, use that to switch to country-specific code, otherwise access the GeoIP DB to determine the country-code, set the cookie, and switch as usual (works even if the user doesn't accept cookies). Make it a session cookie, the user might travel. Be careful in case you have some page caching: it must not ignore the country-code cookie.
Your question mentions a redirect, which could be a country-specific header('Location: ...');
, but you should probably do without that, since it makes things much more complicated, and increases your traffic a bit.
Upvotes: 1
Reputation: 4145
Well, I think you're too much worried, but let's me explain:
For this situation I suggest to:
PS
If you will going to cluster $_SESSION sharing will be the real challenge, so you can look since now to session manager
Upvotes: 1