Pregunta

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!

¿Fue útil?

Solución

Well, I think you're too much worried, but let's me explain:

  1. IP -> country IS an hash table, so I expect tiny time to resolve your query
  2. it's a static information, once resolved can be cached
  3. 100k page view with 40k users mean 1 user per 2.5 page view, a "short" navigation history (I explain later)

For this situation I suggest to:

  1. query the DB using the PHP (put the code in the "head" of execution) and store/cache the country in a cookie and serve the request. A simple if(empty($COOKIE['country'])) will allow to understand if query the DB or not
  2. avoid the redirect to a different site (us.domain.com) you will pass from 2.5 to 3.5 requests per user (~40% more)
  3. when the site need more resources you can add increase your cloud resources OR add a new machine with same address (www.domain.com) but new IP doing DNS round robin, work well with short navigation history.

PS

If you will going to cluster $_SESSION sharing will be the real challenge, so you can look since now to session manager

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top