当前位置: 首页>>代码示例>>PHP>>正文


PHP shm_detach函数代码示例

本文整理汇总了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));
 }
开发者ID:ada-u,项目名称:chocoflake,代码行数:34,代码来源:IdWorkerOnSharedMemory.php

示例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;
}
开发者ID:fixbugs,项目名称:pubfunc-php,代码行数:43,代码来源:pub.serial.php

示例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;
}
开发者ID:KevinStoneCode,项目名称:twmap,代码行数:32,代码来源:kml_lib.php

示例5: destroy

 public function destroy()
 {
     $nbProcess = $this->updateNbProcess(-1);
     if ($nbProcess < 1) {
         shm_remove($this->memory);
     } else {
         shm_detach($this->memory);
     }
 }
开发者ID:CrakLabs,项目名称:ipc-component,代码行数:9,代码来源:ShmMemory.php

示例6: __destruct

 function __destruct()
 {
     if (null !== $this->shmHandle) {
         shm_detach($this->shmHandle);
     }
     if (null !== $this->semHandle) {
         sem_release($this->semHandle);
     }
 }
开发者ID:emente,项目名称:kataii---kata-framework-2.x,代码行数:9,代码来源:event.php

示例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
 }
开发者ID:szrq,项目名称:simple-fork-php,代码行数:13,代码来源:SharedMemory.php

示例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);
     }
 }
开发者ID:hiveclick,项目名称:mojavi,代码行数:13,代码来源:SharedMemory.php

示例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;
 }
开发者ID:justthefish,项目名称:hesper,代码行数:11,代码来源:SharedMemorySegmentHandler.php

示例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);
 }
开发者ID:wapmorgan,项目名称:kvstorage,代码行数:12,代码来源:Shm.php

示例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);
     });
 }
开发者ID:xingcuntian,项目名称:MultiPhreading,代码行数:13,代码来源:Threading.php

示例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);
     }
 }
开发者ID:adnanrahim,项目名称:PHP-Daemon,代码行数:15,代码来源:Shm.php

示例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) {
         /*_*/
     }
 }
开发者ID:justthefish,项目名称:hesper,代码行数:23,代码来源:SharedMemory.php

示例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;
 }
开发者ID:narikenabilli,项目名称:spiritualtablet,代码行数:21,代码来源:interprocessdata.php

示例15: Delete

 function Delete()
 {
     if (!function_exists("shm_attach")) {
         $this->ok = false;
         return;
     }
     shm_remove($this->shmid);
     shm_detach($this->shmid);
 }
开发者ID:BillTheBest,项目名称:1.6.x,代码行数:9,代码来源:class.semaphores.php


注:本文中的shm_detach函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。