You are here

function geoip_open in GeoIP API 7

Same name and namespace in other branches
  1. 6 lib/geoip.inc \geoip_open()
1 call to geoip_open()
geoip_instance in ./geoip.module
Singleton wrapper around geoip_open().

File

lib/geoip.inc, line 337

Code

function geoip_open($filename, $flags) {
  $gi = new GeoIP();
  $gi->flags = $flags;
  if ($gi->flags & GEOIP_SHARED_MEMORY) {
    $gi->shmid = @shmop_open(GEOIP_SHM_KEY, "a", 0, 0);
  }
  else {
    $gi->filehandle = fopen($filename, "rb") or die("Can not open {$filename}\n");
    if ($gi->flags & GEOIP_MEMORY_CACHE) {
      $s_array = fstat($gi->filehandle);
      $gi->memory_buffer = fread($gi->filehandle, $s_array['size']);
    }
  }
  $gi = _setup_segments($gi);
  return $gi;
}