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


PHP shm_put_var函数代码示例

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


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

示例1: write

 public function write($key, $value)
 {
     if ($this->shmId) {
         return shm_put_var($this->shmId, $key, $value);
     }
     return false;
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:7,代码来源:ShmSemaphorBucket.php

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

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

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

示例5: createLock

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

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

示例7: set

 /**
  * @param $key
  * @param $value
  * @param int $size
  */
 public function set($key, $value, $size = 10000)
 {
     $result = $this->attach($key, $size);
     sem_acquire($result['mutex']);
     shm_put_var($result['shm'], $key, $value);
     sem_release($result['mutex']);
 }
开发者ID:bes89,项目名称:sharedmemory,代码行数:12,代码来源:SharedMemory.php

示例8: put

 /**
  * @author Yohann Marillet
  */
 public function put($key = 1, $value = true)
 {
     $res = shm_put_var($this->segment, $key, [$value]);
     if (!$res) {
         throw new \Exception('Cannot put data in semaphore');
     }
     return $this;
 }
开发者ID:ymarillet,项目名称:sknife,代码行数:11,代码来源:SemaphoreShm.php

示例9: set

 /**
  * @see CachePeer::set()
  *
  * @return SysVCachePeer
  */
 function set($key, $value, $ttl = CacheTtl::HOUR)
 {
     Assert::isNumeric($ttl);
     if ($this->isAlive()) {
         shm_put_var($this->getSegmentPtr(), $this->key2int($key), array(self::FIELD_EXPIRES => time() + $ttl, self::FIELD_DATA => $value));
     }
     return $this;
 }
开发者ID:phoebius,项目名称:proof-of-concept,代码行数:13,代码来源:SysVCachePeer.class.php

示例10: set

 public function set()
 {
     $lock = $this->check();
     if ($lock) {
         throw new Exception('Core_Lock_Shm::set Failed. Existing Lock Detected from PID ' . $lock['pid']);
     }
     shm_put_var($this->shm, self::ADDRESS, array('pid' => $this->pid, 'time' => time()));
 }
开发者ID:adnanrahim,项目名称:PHP-Daemon,代码行数:8,代码来源:Shm.php

示例11: set

 /**
  * Set shared memory var
  * @param $var
  */
 public function set($var)
 {
     sem_acquire($this->__mutex);
     //block until released
     shm_put_var($this->__shm, $this->__key, $var);
     //store var
     sem_release($this->__mutex);
     //release mutex
 }
开发者ID:nejtr0n,项目名称:shmestage,代码行数:13,代码来源:SharedMemory.php

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

示例13: lock

 /**
  * if an error like "not enough shared memory left" occurs then set  sysvshm.init_mem to a higher value
  * Lock process without blocking.
  * This method allow protect multiple process running and fast lock validation.
  *
  */
 public function lock()
 {
     $success = sem_acquire($this->_getSemIdentifier());
     shm_put_var($this->_shmId, $this->getIndexerCodeCrc(), $this->_getMicrotimeString());
     if (false === $success) {
         Mage::throwException('FastIndexer: Cannot acquire semaphore lock!');
     }
     $this->_isLocked = true;
 }
开发者ID:ThomasNegeli,项目名称:Magento-FastIndexer,代码行数:15,代码来源:Semaphore.php

示例14: store

 public static function store($key, $value)
 {
     self::getHandle();
     if (!shm_put_var(self::$handle, self::getVarKey($key), $value)) {
         sem_remove(self::$semaphore);
         shm_remove(self::$handle);
         die('couldn\'t write to shared memory.');
     }
     self::release();
 }
开发者ID:mikejw,项目名称:elib-base,代码行数:10,代码来源:Stats.php

示例15: run

 public function run()
 {
     $this->synchronized(function ($thread) {
         $thread->wait();
     }, $this);
     $counter = shm_get_var($this->shmid, 1);
     $counter++;
     shm_put_var($this->shmid, 1, $counter);
     printf("Thread #%lu says: %s\n", $this->getThreadId(), $counter);
 }
开发者ID:xingcuntian,项目名称:example,代码行数:10,代码来源:Synchronizing.php


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