本文整理汇总了PHP中shm_detach函数的典型用法代码示例。如果您正苦于以下问题:PHP shm_detach函数的具体用法?PHP shm_detach怎么用?PHP shm_detach使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了shm_detach函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
shm_remove($this->shmResource);
shm_detach($this->shmResource);
@unlink($this->tmpFileName);
unset($this->shmAdapter, $this->kvs);
}
开发者ID:adammbalogh,项目名称:key-value-store-shared-memory,代码行数:7,代码来源:AbstractKvsSharedMemoryTestCase.php
示例2: generate
/**
* @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));
}
示例3: getNextValueByShareMemory
/**
* 通过本机共享内存件来生成一个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;
}
示例4: Map2GE
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;
}
示例5: destroy
public function destroy()
{
$nbProcess = $this->updateNbProcess(-1);
if ($nbProcess < 1) {
shm_remove($this->memory);
} else {
shm_detach($this->memory);
}
}
示例6: __destruct
function __destruct()
{
if (null !== $this->shmHandle) {
shm_detach($this->shmHandle);
}
if (null !== $this->semHandle) {
sem_release($this->semHandle);
}
}
示例7: dettach
/**
* @return bool
*/
public function dettach()
{
$this->set($this->client_count_key, $this->get($this->client_count_key) - 1);
//如果是最后一个使用的客户端,则删除共享内存
if ($this->get($this->client_count_key) == 0) {
return $this->remove();
}
return shm_detach($this->shm);
//allocate shared memory
}
示例8: __destruct
/**
* Destroys the shared memory segment
*/
function __destruct()
{
if (shm_get_var($this->id, 1) == 1) {
// I am the last listener so kill shared memory space
$this->remove();
} else {
shm_detach($this->id);
shm_put_var($this->id, 1, shm_get_var($this->id, 1) - 1);
}
}
示例9: drop
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;
}
示例10: __destruct
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);
}
示例11: __construct
public function __construct($keyIdentifier = 'MultiPhreading', $MemorySize = 1000000, $perms = 0666)
{
$this->keyIdentifier = $keyIdentifier;
$this->keyLocation = '/tmp/' . $keyIdentifier;
if (!is_file($this->keyLocation)) {
touch($this->keyLocation);
}
$ftOk = ftok($this->keyLocation, 'a');
$this->sharedMemoryId = shm_attach($ftOk, $MemorySize, $perms);
register_shutdown_function(function () {
shm_detach($this->sharedMemoryId);
});
}
示例12: teardown
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);
}
}
示例13: __destruct
public function __destruct()
{
foreach (self::$attached as $segment) {
shm_detach($segment);
}
// sync classes
$segment = shm_attach(self::INDEX_SEGMENT, self::DEFAULT_SEGMENT_SIZE, HESPER_IPC_PERMS);
try {
$index = shm_get_var($segment, 1);
} catch (BaseException $e) {
$index = [];
}
try {
shm_put_var($segment, 1, array_unique(array_merge($index, array_keys(self::$attached))));
} catch (BaseException $e) {
/*_*/
}
try {
shm_detach($segment);
} catch (BaseException $e) {
/*_*/
}
}
示例14: RemoveSharedMem
/**
* 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;
}
示例15: Delete
function Delete()
{
if (!function_exists("shm_attach")) {
$this->ok = false;
return;
}
shm_remove($this->shmid);
shm_detach($this->shmid);
}