本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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>');
}
}
示例7: has
public function has($key)
{
if (shm_has_var($this->shm, $this->shm_key($key))) {
return true;
} else {
return false;
}
}
示例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);
}
示例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;
}
}
示例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>');
}
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}