• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP shm_has_var函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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)) {
         $output->writeln('<info>' . Config::NAME . ' ' . shm_get_var(Config::$sharedId, Config::PID) . ' is running</info>');
         exit;
     }
     if ($input->getOption('debug') === false) {
         if (function_exists('ini_set')) {
             ini_set('error_log', Config::$path . Config::$logsPath . '/error.log');
         }
         fclose(STDIN);
         fclose(STDOUT);
         fclose(STDERR);
         $STDIN = fopen('/dev/null', 'r');
         $STDOUT = fopen(Config::$path . Config::$logsPath . '/appilication.log', 'ab');
         $STDERR = fopen(Config::$path . Config::$logsPath . '/error.log', 'ab');
     }
     $phpcron = new PHPCron(Entries::getCrontab());
     $phpcron->execute();
 }
开发者ID:dmamontov,项目名称:symfony-phpcron,代码行数:25,代码来源:ExecuteCommand.php


示例17: __construct

 /**
  * Constructor
  */
 function __construct($name, $timeoutms = 5000)
 {
     if (!function_exists('shm_has_var')) {
         throw new BaseException("No mutex support on this platform");
     }
     $this->_lockname = $name;
     // Block until lock can be acquired
     if (Mutex::$instance == 0) {
         Console::debug("Creating mutex manager");
         Mutex::$resource = shm_attach(Mutex::SHM_KEY);
         if (!shm_has_var(Mutex::$resource, Mutex::SHM_LOCKS)) {
             shm_put_var(Mutex::$resource, Mutex::SHM_LOCKS, array());
         }
     }
     $this->enterCriticalSection();
     Console::debug("Waiting for lock %s", $this->_lockname);
     $t = new timer(true);
     while (true) {
         $ls = shm_get_var(Mutex::$resource, Mutex::SHM_LOCKS);
         if (!isset($ls[$name])) {
             break;
         }
         usleep(100000);
         if ($t->getElapsed() > $timeoutms / 1000) {
             $this->exitCriticalSection();
             throw new MutexException("Timed out waiting for lock");
         }
     }
     Console::debug("Acquiring lock %s", $this->_lockname);
     $ls = shm_get_var(Mutex::$resource, Mutex::SHM_LOCKS);
     $ls[$name] = true;
     shm_put_var(Mutex::$resource, Mutex::SHM_LOCKS, $ls);
     Mutex::$instance++;
     $this->_lockstate = true;
     $this->exitCriticalSection();
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:39,代码来源:mutex.php


示例18: remove_var

 public function remove_var($varname, $autolock = FALSE)
 {
     $varkey = $this->_gen_key($varname);
     if ($autolock) {
         sem_acquire($this->sem);
     }
     if (!shm_has_var($this->shm_id, $varkey)) {
         $result = TRUE;
     } else {
         $result = shm_remove_var($this->shm_id, $varkey);
     }
     if ($autolock) {
         sem_release($this->sem);
     }
     return $result;
 }
开发者ID:hwsyy,项目名称:php-backend-server,代码行数:16,代码来源:ShareMemory.class.php


示例19: canRevert

 public function canRevert()
 {
     $ftok = ftok("/dev/shm/ipc_firewall", "a");
     $segment = shm_attach($ftok, 1048576, 0666);
     // Create/attach to 10k shared memory segment
     if (!shm_has_var($segment, 0)) {
         // Hasn't been used
         return false;
     }
     $settings = shm_get_var($segment, 0);
     if (isset($settings['timestamp']) && !isset($settings['confirmed'])) {
         return $settings['timestamp'];
     }
     return false;
 }
开发者ID:ntadmin,项目名称:firewall,代码行数:15,代码来源:Firewall.class.php


示例20: isExists

 /**
  * (non-PHPdoc)
  * @see Lexik\Bundle\MaintenanceBundle\Drivers.AbstractDriver::isExists()
  */
 public function isExists()
 {
     if ($this->shmId) {
         if (!shm_has_var($this->shmId, self::VARIABLE_KEY)) {
             return false;
         }
         $data = shm_get_var($this->shmId, self::VARIABLE_KEY);
         return $data == self::VALUE_TO_STORE;
     }
     return false;
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:15,代码来源:ShmDriver.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP shm_put_var函数代码示例发布时间:2022-05-24
下一篇:
PHP shm_get_var函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap