public function tearDown() { shm_remove($this->shmResource); shm_detach($this->shmResource); @unlink($this->tmpFileName); unset($this->shmAdapter, $this->kvs); }
/** * 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); }
public function destroy() { $nbProcess = $this->updateNbProcess(-1); if ($nbProcess < 1) { shm_remove($this->memory); } else { shm_detach($this->memory); } }
public static function store($key, $value) { self::getHandle(); if (!shm_put_var(self::$handle, self::getVarKey($key), $value)) { sem_remove(self::$semaphore); shm_remove(self::$handle); die('couldn\'t write to shared memory.'); } self::release(); }
/** * remove shared memory. * you should know that it maybe does not work. * * @return bool */ public function remove() { //dallocate shared memory if (!shm_remove($this->shm)) { return false; } $this->dettach(); // shm_remove maybe not working. it likes a php bug. unset($this->shm); return true; }
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 remove() { if (!shm_remove($this->memory)) { throw new StorageException("Could not release shared memory."); } $this->memory = null; if (!sem_remove($this->semaphore)) { throw new StorageException("Could not remove semaphore."); } $this->semaphore = null; }
public function destroy() { if (!is_null($this->shm_res) && is_resource($this->shm_res)) { shm_remove($this->shm_res); if (file_exists($this->tmp_file)) { unlink($this->tmp_file); } $this->shm_res = null; $this->logger->debug('Delete shared memory resource'); } }
public function __destruct() { if ($this->changed) { if (shm_put_var($this->res, self::DEFAULT_VAR_ID, $this->data) === false) { $length = strlen($this->data); shm_remove($this->res); $this->res = shm_attach($this->id, ceil($length * 1.25)); shm_put_var($this->res, self::DEFAULT_VAR_ID, $this->data); } } shm_detach($this->res); }
public function teardown() { // Check shm validity before shm_get_var, return directly if NULL or FALSE // This may happen when check_environment fail. if ($this->shm) { $lock = shm_get_var($this->shm, self::ADDRESS); } else { return; } // If this PID set this lock, release it if ($lock['pid'] == $this->pid) { shm_remove($this->shm); shm_detach($this->shm); } }
/** * 获取故障节点列表 * @return array */ public static function getBadAddressList($use_cache = true) { // 没有加载扩展 if (!extension_loaded('sysvshm')) { self::$badAddressList = array(); return false; } // 还没有初始化故障节点 if (null === self::$badAddressList || !$use_cache) { // 是否有故障节点 if (!shm_has_var(self::getShmFd(), RPC_BAD_ADDRESS_KEY2)) { self::$badAddressList = array(); } else { // 获取故障节点 $bad_address_list = shm_get_var(self::getShmFd(), RPC_BAD_ADDRESS_KEY2); if (false === $bad_address_list || !is_array($bad_address_list)) { // 出现错误,可能是共享内存写坏了,删除共享内存 $ret = shm_remove(self::getShmFd()); self::$badAddressShmFd = shm_attach(self::BAD_ASSRESS_LIST_SHM_KEY); self::$badAddressList = array(); // 这个不要再加锁了 self::checkConfigMd5(); } else { self::$badAddressList = $bad_address_list; } } } return self::$badAddressList; }
/** * 获取故障节点列表 * @return array */ public static function getBadAddressList($use_cache = true) { // 还没有初始化故障节点 if (null === self::$badAddressList || !$use_cache) { $bad_address_list = array(); if (self::$shmEnable && shm_has_var(self::getShmFd(), self::SHM_BAD_ADDRESS_KEY)) { // 获取故障节点 $bad_address_list = shm_get_var(self::getShmFd(), self::SHM_BAD_ADDRESS_KEY); if (!is_array($bad_address_list)) { // 可能是共享内寻写怀了,重新清空 self::getMutex(); shm_remove(self::getShmFd()); self::releaseMutex(); self::$badAddressShmFd = null; self::$badAddressList = array(); } else { self::$badAddressList = $bad_address_list; } } else { self::$badAddressList = $bad_address_list; } } return self::$badAddressList; }
public function remove() { shm_remove($this->shm_id); return TRUE; }
/** * Force release */ public function destroy() { sem_remove($this->__mutex); shm_remove($this->__shm); }
function Delete() { if (!function_exists("shm_attach")) { $this->ok = false; return; } shm_remove($this->shmid); shm_detach($this->shmid); }
/** * Remove all data */ public function remove() { return @shm_remove($this->db); }
public function destroy() { shm_remove($this->shmId); }
function utils_mem_idle_close() { $shmid =& $GLOBALS['CHILDRENIDLE_SHMID']; shm_remove($shmid); shm_detach($shmid); }
/** * Remove the shared memory segment. */ public function destroy() { $res = shm_remove($this->ipc); @unlink($this->ipcFile); }
public function remove() { if (is_resource($this->id)) { shm_remove($this->id); } if (file_exists($this->file)) { unlink($this->file); } }
public function destroy() { if (shm_has_var($this->shm, 1)) { shm_remove_var($this->shm, 1); } shm_remove($this->shm); }
/** * When the parent process exits, cleans shared memory and semaphore. * * This is called using 'register_shutdown_function' pattern. * @see http://php.net/register_shutdown_function */ public function onShutdown() { if (posix_getpid() == $this->_nParentPid) { $this->_log('INFO: Parent shutdown, cleaning memory...'); @shm_remove($this->_hShm) && @shm_detach($this->_hShm); @sem_remove($this->_hSem); } }
/** * Finish create an asynchronous task * @return void * @access public * @final */ public final function __destruct() { if (@shm_has_var(self::$shmId, 112112105100) && shm_get_var(self::$shmId, 112112105100) == getmypid()) { shm_remove(self::$shmId); } }
<?php $arr = array(0, 1, 2, 3, 4, 5, 6); if (!($nShmID = shm_attach(ftok(__FILE__, 'i'), 1024))) { die("create shared memory failed.\n"); } $nVarKey = 1; if (!shm_put_var($nShmID, $nVarKey, $arr)) { die("failed to put var\n"); } if (!($arr1 = shm_get_var($nShmID, $nVarKey))) { die("failed to get arr1\n"); } var_dump($arr1); array_pop($arr1); if (!($arr2 = shm_get_var($nShmID, $nVarKey))) { die("failed to get arr2\n"); } if ($arr != $arr2) { echo "get a copy\n"; } else { echo "get a reference\n"; } var_dump($arr2); if (!shm_remove($nShmID)) { die("failed to remove shared memory\n"); }
public function __destruct() { shm_remove($this->shared_memory_segment); }
/** * Destroys any shared memory resources created during the lifetime of this * process, without regard to whether they contain any data. This method * should never be called in typical code but is useful for cleanup in * some testing situations where we have shared memory resources keyed on * the names of dynamically-generated classes. */ public static function destroyAll() { if (self::$_activeShmResources) { while (!self::$_activeShmResources->isEmpty()) { $resource = self::$_activeShmResources->dequeue(); if (is_resource($resource)) { if (self::$_useSysV) { shm_remove($resource); } else { fclose($resource); } } else { unlink($resource); } } } }
/** * Removes and detaches shared memory * * @access private * @return boolean */ private function RemoveSharedMem() { if (isset($this->mutexid) && $this->mutexid !== false && (isset($this->memid) && $this->memid !== false)) { @sem_acquire($this->mutexid); $memid = $this->memid; $this->memid = false; @sem_release($this->mutexid); @sem_remove($this->mutexid); @shm_remove($memid); @shm_detach($memid); $this->mutexid = false; return true; } return false; }
echo "failed\n"; exit(1); } $index = $ret; var_dump(shm_has_var($index, 1234)); shm_put_var($index, 1234, "test"); var_dump(shm_has_var($index, 1234)); $pid = pcntl_fork(); if ($pid == 0) { $ret = shm_attach($index); $ret = shm_get_var($index, 1234); if ($ret !== "test") { echo "oops\n"; exit(1); } shm_remove_var($index, 1234); shm_detach($index); exit(0); } // Verifying shm_remove_var worked, this is not sure test though. $ret = shm_get_var($index, 1234); for ($i = 0; $i < 1000; $i++) { if ($ret === false) { break; } usleep(1000); $ret = shm_get_var($index, 1234); } var_dump($ret === false); shm_remove($index); pcntl_waitpid($pid, $status);
/** * 销毁共享内存以及消息队列 * @return void */ protected static function removeShmAndQueue() { if (self::$shmId) { shm_remove(self::$shmId); } if (self::$queueId) { msg_remove_queue(self::$queueId); } }
function delete() { $this->logger->debug(sprintf("Delete shm segment (key: 0x%08x)", $this->key)); shm_remove($this->shm); shm_detach($this->shm); }