You are here

public static function Database::shmTeardown in Smart IP 6.2

Same name and namespace in other branches
  1. 7.2 includes/vendor/ip2location/ip2location-php/IP2Location.php \IP2Location\Database::shmTeardown()

Tear down a shared memory segment created for the given file

@access public @static

Parameters

string $file Filename of the BIN database whise segment must be deleted:

Throws

\Exception

File

includes/vendor/ip2location/ip2location-php/IP2Location.php, line 790

Class

Database
IP2Location database class

Namespace

IP2Location

Code

public static function shmTeardown($file) {

  // verify the shmop extension is loaded
  if (!extension_loaded('shmop')) {
    throw new \Exception(__CLASS__ . ": Please make sure your PHP setup has the 'shmop' extension enabled.", self::EXCEPTION_NO_SHMOP);
  }

  // Get actual file path
  $rfile = realpath($file);

  // If the file cannot be found, except away
  if (false === $rfile) {
    throw new \Exception(__CLASS__ . ": Database file '{$file}' does not seem to exist.", self::EXCEPTION_DBFILE_NOT_FOUND);
  }
  $shmKey = self::getShmKey($rfile);

  // Try to open the memory segment for writing
  $shmId = @shmop_open($shmKey, 'w', 0, 0);
  if (false === $shmId) {
    throw new \Exception(__CLASS__ . ": Unable to access shared memory block '{$shmKey}' for writing.", self::EXCEPTION_SHMOP_WRITING_FAILED);
  }

  // Delete and close the descriptor
  shmop_delete($shmId);
  shmop_close($shmId);
}