fred727
fred727

Reputation: 2819

Différence between installing geoip as a PHP module VS as an apache2 module

If apache module is installed, you get country code with :

$_SERVER['GEOIP_COUNTRY_CODE']

With the PHP module/library, you use :

geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])

What is the difference (performance etc...) between these 2 solutions ? Which one is the best ? For which need ?

I think apache module loaded extention in memory for every request, which could be bad for performances. (Or you have to set rules with GeoIPEnable Off/On but this is not always easy...) So If you need geoip on some pages only, is it better for performance to use PHP module ?

Upvotes: 2

Views: 841

Answers (1)

preinheimer
preinheimer

Reputation: 3722

They're roughly equivalent in performance. We were also curious, so we did some testing both on Digital Ocean VMs and locally with vagrant. The results were the same: Using the Apache Extension, PHP Extension, or PHP Library all delivered fantastic results. No real hit vs not doing GeoIP at all.

You can disable GeoIP within Apache on a directory or file basis using .htaccess, so if you would like to disable it for some areas you're free to do so there as well.

We've blogged about our tests, with details on how to reproduce: GeoIP Performance Examined

Upvotes: 2

Related Questions