function Map2GE($x, $y) { if (0) { $SHM_KEY = ftok(__FILE__, chr(4)); $data = shm_attach($SHM_KEY, 102400, 0666); $result = shm_get_var($data, 1); $r = $result[$x][$y]; if (isset($r)) { shm_detach($data); return $r; } } // ×¥¿ $r = t67to97($x, $y); $x = $r[0]; $y = $r[1]; $proj = "proj -I +proj=tmerc +ellps=aust_SA +lon_0=121 +x_0=250000 +k=0.9999"; $ret = shell_exec("echo {$x} {$y} | {$proj}"); if (preg_match("/(\\d+)d(\\d+)'([\\d.]+)\"E\\s+(\\d+)d(\\d+)'([\\d.]+)\"N/", $ret, $matches)) { list($junk, $ed, $em, $es, $nd, $nm, $ns) = $matches; $r[0] = $ed + $em / 60 + $es / 3600; $r[1] = $nd + $nm / 60 + $ns / 3600; if (0) { $result[$x][$y] = $r; shm_put_var($data, 1, $result); shm_detach($data); } return $r; } return FALSE; // exit; }
/** * Memory alloc */ protected function alloc() { if (null !== $this->memory) { return; } $this->memory = shm_attach(ftok(__FILE__, $this->identifier), $this->segmentSize, 0644); }
public function __construct(string $namespace = null) { if (is_null($namespace)) { $namespace = isset($_SERVER['PWD']) ? $_SERVER['PWD'] : 'SHM'; } $this->_shmid = shm_attach(crc32($namespace)); }
/** * Flush entire cache. */ function flush() { parent::flush(); // remove and reconnect to the SHM block shm_remove($this->shmid); $this->shmid = shm_attach($this->shmkey, $this->memsize, 0600); }
/** * @param int $id * @param Lock $lock */ public function __construct($id, LockInterface $lock) { $this->id = $id; $this->lock = $lock; $this->memory = shm_attach($this->id); $this->updateNbProcess(+1); }
public function __construct() { if (!function_exists('shm_attach')) { throw new \RuntimeException('You need to enabled Shared Memory System V(see more "Semaphore")'); } $this->shared_memory_segment = shm_attach(time() + rand(1, 1000)); }
/** * Wake up from a sleep */ function __wakeup() { $this->id = sem_get($this->key); shm_attach($this->id); $this->refreshMemoryVarList(); shm_put_var($this->id, 1, shm_get_var($this->id, 1) + 1); }
/** * 通过本机共享内存件来生成一个auto_increment序列 * * 序列类似MySQL的auto_increment * * @access private * @param void * @return mixed */ function getNextValueByShareMemory() { $addr = '127.0.0.1'; if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $addr = $_SERVER['HTTP_X_FORWARDED_FOR']; } elseif (!empty($_SERVER['SERVER_ADDR'])) { $addr = $_SERVER['SERVER_ADDR']; } $skey = 'global_serial_generator_seed_' . $addr; $ikey = crc32($skey); $sem = $shm = null; $retry_times = 1; do { $sem = sem_get($ikey, 1, 0777); $shm = shm_attach($ikey, 128, 0777); if (is_resource($sem) && is_resource($shm)) { break; } $cmd = "ipcrm -M 0x00000000; ipcrm -S 0x00000000; ipcrm -M {$ikey} ; ipcrm -S {$ikey}"; $last_line = exec($cmd, $output, $retval); } while ($retry_times-- > 0); if (!sem_acquire($sem)) { return false; } $next_value = false; if (shm_has_var($shm, $ikey)) { shm_put_var($shm, $ikey, $next_value = shm_get_var($shm, $ikey) + 1); } else { shm_put_var($shm, $ikey, $next_value = 1); } $shm && shm_detach($shm); $sem && sem_release($sem); return $next_value; }
/** * @return IdValue */ public function generate() { $timestamp = $this->generateTimestamp(); // Acquire semaphore $semaphore = sem_get($this->semaphoreId); sem_acquire($semaphore); // Attach shared memory $memory = shm_attach(self::SHM_KEY); $sequence = 0; if (!is_null($this->lastTimestamp) && $timestamp->equals($this->lastTimestamp)) { // Get $sequence = shm_get_var($memory, self::SHM_SEQUENCE) + 1 & $this->config->getSequenceMask(); // Increment sequence shm_put_var($memory, self::SHM_SEQUENCE, $sequence); if ($sequence === 0) { usleep(1000); $timestamp = $this->generateTimestamp(); } } else { // Reset sequence if timestamp is different from last one. $sequence = 0; shm_put_var($memory, self::SHM_SEQUENCE, $sequence); } // Detach shared memory shm_detach($memory); // Release semaphore sem_release($semaphore); // Update lastTimestamp $this->lastTimestamp = $timestamp; return new IdValue($timestamp, $this->regionId, $this->serverId, $sequence, $this->calculate($timestamp, $this->regionId, $this->serverId, $sequence)); }
public function open() { $this->shm = shm_attach($this->ipckey, 256000, 0666); if (!$this->shm) { throw new \Exception("Could not open shared memory segment"); } }
private function __construct() { $this->id = @shm_attach(55, 10000, 0600); if (!$this->id) { throw new \Exception('Нет доступа к общей памяти'); } }
/** * Create shared memory block */ private function attach() { $this->__key = ftok($this->__path, $this->__proj_id); $this->__shm = shm_attach($this->__key, $this->__size); //allocate shared memory $this->__mutex = sem_get($this->__key, 1); //create mutex with same key }
protected function initializeShm() { if (null !== $this->shmHandle) { return; } $this->shmHandle = shm_attach($this->getId(), 60 * 1024); $this->semHandle = sem_get($this->getId()); }
public function open() { $perms = $this->config['shared_memory.permissions']; $size = $this->config['rabbitmq.max_workers'] * 44; $file = $this->tmp_file; $this->shm_res = shm_attach(ftok($file, 'L'), $size, $perms); $this->logger->debug('Opening shared memory resource with id: [' . intval($this->shm_res) . '] on file [' . $this->tmp_file . ']'); }
function pleac_Sharing_Variables_in_Different_Processes() { // sharetest - test shared variables across forks $SHM_KEY = ftok(__FILE__, chr(1)); $handle = sem_get($SHM_KEY); $buffer = shm_attach($handle, 1024); // The original recipe has an INT signal handler here. However, it // causes erratic behavior with PHP, and PHP seems to do the right // thing without it. for ($i = 0; $i < 10; $i++) { $child = pcntl_fork(); if ($child == -1) { die('cannot fork'); } elseif ($child) { $kids[] = $child; // in case we care about their pids } else { squabble(); exit; } } while (true) { print 'Buffer is ' . shm_get_var($buffer, 1) . "\n"; sleep(1); } die('Not reached'); function squabble() { global $handle; global $buffer; $i = 0; $pid = getmypid(); while (true) { if (preg_match("/^{$pid}\\b/", shm_get_var($buffer, 1))) { continue; } sem_acquire($handle); $i++; shm_put_var($buffer, 1, "{$pid} {$i}"); sem_release($handle); } } // Buffer is 14357 1 // Buffer is 14355 3 // Buffer is 14355 4 // Buffer is 14354 5 // Buffer is 14353 6 // Buffer is 14351 8 // Buffer is 14351 9 // Buffer is 14350 10 // Buffer is 14348 11 // Buffer is 14348 12 // Buffer is 14357 10 // Buffer is 14357 11 // Buffer is 14355 13 // ... }
protected function connect($vbb90bf734107ea3b2f4c14a5d4bc4f91) { $this->segmentKey = shm_attach($vbb90bf734107ea3b2f4c14a5d4bc4f91, self::segmentSize, self::segmentPermissions); if ($v6a992d5529f459a44fee58c733255e86 = @shm_get_var($this->segmentKey, 1)) { $this->index = $v6a992d5529f459a44fee58c733255e86; } else { shm_put_var($this->segmentKey, 1, array(0 => false)); } }
/** * @brief * * @param * @return */ function __construct($filename) { if (!file_exists($filename)) { touch($filename); chmod($filename, 0666); } $this->ipckey = ftok($filename, 'i'); $this->shmres = shm_attach($this->ipckey, 1 << 16); }
public function __construct($channel) { $this->ipcFile = sys_get_temp_dir() . "/{$channel}.ipc"; @touch($this->ipcFile); $this->ipc = ftok($this->ipcFile, 's'); // s for shm $this->ipc = shm_attach($this->ipc); // leave $memsize to php.ini }
/** * connect shared memory * * @param string $file */ public function attach($file = __FILE__) { //增加客户端连接数 $file = basename($file); $tmp_file = '/tmp/' . substr($file, 0, strrpos($file, '.')) . 'lock'; touch($tmp_file); $key = ftok($tmp_file, 'a'); $this->shm = shm_attach($key, $this->size); //allocate shared memory }
/** * Constructor shmDriver * * @param Translator $translator Translator service * @param array $options Options driver */ public function __construct($translator, array $options = array()) { parent::__construct($translator, $options); $key = ftok(__FILE__, 'm'); $this->shmId = shm_attach($key, 100, 0666); if (!$this->shmId) { throw new \RuntimeException('Can\'t allocate shared memory'); } $this->options = $options; }
public function setUp() { $this->tmpFileName = tempnam('/tmp', 'KVS'); $this->shmResource = shm_attach(ftok($this->tmpFileName, 'a')); if (!$this->shmResource) { die('Unable to create the shared memory segment'); } $this->shmAdapter = new SharedMemoryAdapter($this->shmResource); $this->kvs = new KeyValueStore($this->shmAdapter); }
/** * init shared memory */ public function attach() { //增加客户端连接数 $tmp_file = '/tmp/' . basename(__FILE__); touch($tmp_file); $key = ftok($tmp_file, 'a'); $this->shm = shm_attach($key, $this->size); //allocate shared memory $this->set($this->client_count_key, $this->get($this->client_count_key) + 1); }
public function __construct($file, $scope = self::SCOPE_APP, $size = 65535) { $mf = $file . ($scope == self::SCOPE_PID) ? '.' . getmypid() : ''; if (!file_exists($mf)) { touch($mf); } $this->key = fileinode($mf); $this->debug("SHM key: %d", $this->key); $this->shm = shm_attach($this->key, $size, 0700); }
/** * @param $streamUrl * @param $videoLength * @param $videoFormat * @param $storagePath * @param DB $db */ public function __construct($streamUrl, $videoLength, $videoFormat, $storagePath, DB $db) { $this->streamUrl = $streamUrl; $this->videoLength = $videoLength; $this->videoFormat = $videoFormat; $this->storagePath = $storagePath; $this->db = $db; $this->sharedMemoryId = shm_attach(ftok(__FILE__, 'A') . time() % 1000); shm_put_var($this->sharedMemoryId, $this->getHashKey('pid'), getmypid()); }
/** * @param $key * @param $size * @throws InvalidArgumentException * @return array */ protected function attach($key, $size) { if (!array_key_exists($key, $this->values)) { if (!is_long($key)) { throw new InvalidArgumentException(sprintf('Expected type long for "key" but "%s" given.', gettype($key))); } $this->values[$key] = array('shm' => shm_attach($key, $size), 'mutex' => sem_get($key, 1)); } return $this->values[$key]; }
public function attach() { try { $this->shm_id = shm_attach($this->shm_key, $this->shm_size); // 初始化信号量 $this->sem = sem_get($this->sem_key, 1); } catch (Exception $e) { return FALSE; } return TRUE; }
public function open() { $shmKey = ftok(__FILE__, $this->projectId); $this->shmId = shm_attach($shmKey); // TEST_CREATIVES * TEST_ZONES * 1024 $ret = (bool) $this->shmId; if (!$ret) { echo __LINE__; } return $ret; }
public function drop() { try { $shm = shm_attach($this->id, self::SEGMENT_SIZE, HESPER_IPC_PERMS); } catch (BaseException $e) { return false; } $result = shm_remove($shm); shm_detach($shm); return $result; }
public function __construct($ns, $memSize = null) { if (!$memSize) { $memSize = 1000; } if (array_key_exists($ns, self::$nsKeyCache)) { $this->shmId = self::$nsKeyCache[$ns]; } else { $tmp = tempnam('/tmp', $this->forgeKey($ns)); self::$nsKeyCache[$ns] = $this->shmId = shm_attach(ftok($tmp, 'a'), $memSize); } }
/** * On any *nix use the commands ipcs and ipcrm to work with the memory * @return resource */ protected function _getSemIdentifier() { if (null !== $this->_semId) { return $this->_semId; } $this->_semId = sem_get($this->getIndexerCodeCrc(), 8, 0666); if (false === $this->_semId) { Mage::throwException('FastIndexer: Cannot create semaphore id lock for ' . $this->getIndexerCode()); } $this->_shmId = shm_attach($this->getIndexerCodeCrc(), 128); return $this->_semId; }