Skip to content

4.7.4 Configuration Ip2location BIN File Access Mode

Gurdeep Singh (Guru) edited this page Aug 12, 2024 · 2 revisions

Configuration - Ip2location - BIN File Access Mode

PHPFirewall uses ip2location provided BIN file and libraries to perform the lookup. The ip2location library for PHP is located at: https://github.com/chrislim2888/IP2Location-PHP-Module

The above library provides methods to extract data from the BIN file using the following 3 modes:

  1. FILE_IO
  2. SHARED_MEMORY
  3. MEMORY_CACHE.

Default mode is FILE_IO. The SHARED_MEMORY utilizes PHP Shmop functions to store data in the systems shared memory space and MEMORY_CACHE utilizes php allocated memory space (using php.ini). Regardless of what you choose, you need to make sure your system has that much amount of memory to load the whole database into the memory to perform the lookups. The IP2Location-PHP-Module will check the memory allocation and throw an exception if there is not enough memory. In that case, you can switch to FILE_IO.

NOTE: I have tested the above lookups and would advice to load the file into SHARED_MEMORY or MEMORY_CACHE for a faster lookup. If memory is an issue, FILE_IO also performed well. In the end, PHPFirewall saves the lookups in a separate database and indexes them. So, PHPFirewall does not touch the BIN file after the first successful lookup is made and indexed.

Via CLI

admin@phpterminal:firewall(config)# set ip2location bin access mode
...
OPTIONS: [SHARED_MEMORY | MEMORY_CACHE | FILE_IO]

BIN ACCESS MODE (FILE_IO) : MEMORY_CACHE

SET IP2LOCATION BIN ACCESS MODE OUTPUT
...
FIREWALL DETAILS > IP2LOCATION_BIN_ACCESS_MODE : MEMORY_CACHE
...
admin@phpterminal:firewall(config)# 

Via PHP Firewall Class

$firewall->setIp2locationBinAccessMode('MEMORY_CACHE');