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


PHP shm_has_var函数代码示例

本文整理汇总了PHP中shm_has_var函数的典型用法代码示例。如果您正苦于以下问题:PHP shm_has_var函数的具体用法?PHP shm_has_var怎么用?PHP shm_has_var使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了shm_has_var函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: set

 public function set($key, $value, $no_cas = false)
 {
     if (!$this->isOpen()) {
         $this->open();
     }
     $this->enterCriticalSection($this->ipckey);
     $this->debug("SHM set: {$key} = {$value}");
     $key = strtolower($key);
     $idx = $this->props[$key];
     if (!$no_cas && shm_has_var($this->shm, $idx) && !empty($this->hashes[$key])) {
         $var = shm_get_var($this->shm, $idx);
         $check = md5($var);
         if ($this->hashes[$key] == $check) {
             $this->debug("CAS check: Key not modified: {$key}");
             shm_put_var($this->shm, $idx, $value);
             $ok = true;
         } else {
             $this->debug("CAS check: Key modified, write blocked: {$key}");
             $ok = false;
         }
     } else {
         $this->debug("CAS check: Check disabled for set: {$key}");
         $ok = true;
         shm_put_var($this->shm, $idx, $value);
     }
     if ($ok) {
         $hash = md5($value);
         $this->hashes[$key] = $hash;
         $this->debug("CAS hash for {$key} is now {$hash}");
     }
     $this->leaveCriticalSection();
     return $ok;
 }
开发者ID:noccy80,项目名称:cherryphp,代码行数:33,代码来源:ipcsharedobject.php

示例3: has

 /**
  * Test if has datas with $uid key
  * @param mixed $uid
  * @return boolean
  */
 public function has($uid)
 {
     if (null === $this->memory) {
         return false;
     }
     return shm_has_var($this->memory, $uid);
 }
开发者ID:cityware,项目名称:city-shared-memory,代码行数:12,代码来源:Bloc.php

示例4: __get

 public function __get($name)
 {
     $name = $this->intkey($name);
     if (shm_has_var($this->ipc, $name)) {
         return shm_get_var($this->ipc, $name);
     }
     return NULL;
 }
开发者ID:Victopia,项目名称:prefw,代码行数:8,代码来源:SharedMemory.php

示例5: get

 /**
  * {@inheritdoc}
  */
 public function get()
 {
     if (shm_has_var($this->shared_memory_segment, self::$SEGMENT_VAR_ID)) {
         $data = shm_get_var($this->shared_memory_segment, self::$SEGMENT_VAR_ID);
         shm_remove_var($this->shared_memory_segment, self::$SEGMENT_VAR_ID);
         return $data;
     }
 }
开发者ID:vatson,项目名称:isolated-callback,代码行数:11,代码来源:SharedMemory.php

示例6: execute

 /**
  * Execution commands.
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (is_null(Config::$sharedId) == false && @shm_has_var(Config::$sharedId, Config::STATUS)) {
         $output->writeln('<info>' . shm_get_var(Config::$sharedId, Config::STATUS) . '</info>');
     } else {
         $output->writeln('<comment>' . Config::NAME . ' not running</comment>');
     }
 }
开发者ID:dmamontov,项目名称:symfony-phpcron,代码行数:13,代码来源:StatusCommand.php

示例7: has

 public function has($key)
 {
     if (shm_has_var($this->shm, $this->shm_key($key))) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:millken,项目名称:ypf,代码行数:8,代码来源:Shm.php

示例8: __get

 public function __get($k)
 {
     $key = crc32($k);
     if (!shm_has_var($this->sharedMemoryId, $key)) {
         return null;
     }
     return shm_get_var($this->sharedMemoryId, $key);
 }
开发者ID:xingcuntian,项目名称:MultiPhreading,代码行数:8,代码来源:Threading.php

示例9: set

 public function set($index, $value, $overwrite = false)
 {
     if ($overwrite || !shm_has_var($this->shm, $index) || $this->data[$index] == shm_get_var($this->shm, $index)) {
         shm_put_var($this->shm, $index, $value);
         return true;
     } else {
         return false;
     }
 }
开发者ID:noccy80,项目名称:cherryphp,代码行数:9,代码来源:sharedmem.php

示例10: execute

 /**
  * Execution commands.
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (is_null(Config::$sharedId) == false && @shm_has_var(Config::$sharedId, Config::PID)) {
         $process = new Process('ps o pid --ppid ' . shm_get_var(Config::$sharedId, Config::PID));
         $process->run();
     } else {
         $output->writeln('<comment>' . Config::NAME . ' not running</comment>');
     }
 }
开发者ID:dmamontov,项目名称:symfony-phpcron,代码行数:14,代码来源:CancelCommand.php

示例11: __construct

 public function __construct($id, $startSize = 10240)
 {
     $this->id = $id;
     $this->res = shm_attach($id, $startSize);
     if (!shm_has_var($this->res, self::DEFAULT_VAR_ID)) {
         $this->data = array();
         $this->changed = true;
     } else {
         $this->data = shm_get_var($this->res, self::DEFAULT_VAR_ID);
     }
 }
开发者ID:wapmorgan,项目名称:kvstorage,代码行数:11,代码来源:Shm.php

示例12: remove

 public function remove(string $key) : bool
 {
     if (isset($this->_cache[$key])) {
         unset($this->_cache[$key]);
     }
     $key = crc32($key);
     if (shm_has_var($this->_shmid, $key)) {
         return shm_remove_var($this->_shmid, $key);
     } else {
         return false;
     }
 }
开发者ID:boyxp,项目名称:bluefin-base,代码行数:12,代码来源:shm.php

示例13: readInc

 /**
  * @param int $pid
  *
  * @return int
  */
 private function readInc($pid)
 {
     $res = shm_attach($pid);
     if (!shm_has_var($res, 0)) {
         shm_put_var($res, 0, 0);
     }
     $inc = shm_get_var($res, 0);
     if ($inc === 16777215) {
         $inc = 0;
     }
     ++$inc;
     shm_put_var($res, 0, $inc);
     return $inc;
 }
开发者ID:saxulum,项目名称:saxulum-mongoid,代码行数:19,代码来源:MongoId.php

示例14: get

 protected function get()
 {
     $lock = array();
     if (shm_has_var($this->shm, self::ADDRESS)) {
         $lock = shm_get_var($this->shm, self::ADDRESS);
     } else {
         return false;
     }
     // Ensure we're not seeing our own lock
     if ($lock['pid'] == $this->pid) {
         return false;
     }
     // If it's expired...
     if ($lock['time'] + $this->ttl + Core_Lock_Lock::$LOCK_TTL_PADDING_SECONDS >= time()) {
         return $lock;
     }
     return false;
 }
开发者ID:adnanrahim,项目名称:PHP-Daemon,代码行数:18,代码来源:Shm.php

示例15: _initClockSeq

 protected static function _initClockSeq()
 {
     $shmId = shm_attach(self::$_shmKey);
     self::$_clockSeq = shm_get_var($shmId, self::$_clockSeqKey);
     if (self::$_clockSeq === false) {
         $semId = sem_get(self::$_semKey);
         sem_acquire($semId);
         //blocking
         if (shm_has_var($shmId, self::$_clockSeqKey)) {
             self::$_clockSeq = shm_get_var($shmId, self::$_clockSeqKey);
         } else {
             // 0x8000 variant (2 bits)
             // clock sequence (14 bits)
             self::$_clockSeq = 0x8000 | mt_rand(0, (1 << 14) - 1);
             shm_put_var($shmId, self::$_clockSeqKey, self::$_clockSeq);
         }
         sem_release($semId);
     }
     shm_detach($shmId);
 }
开发者ID:duoshuo,项目名称:uuid,代码行数:20,代码来源:Uuid.php


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