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


PHP sem_get函数代码示例

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


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

示例1: __construct

 function __construct()
 {
     $this->logger = Logger::getLogger(__CLASS__);
     $this->db = $this->getContainer()->adodb;
     $this->lastCleanup = new Scalr_System_Ipc_Shm(array("name" => "scalr.cronjob.poller.lastCleanup"));
     $this->cleanupSem = sem_get(Scalr_System_OS::getInstance()->tok("scalr.cronjob.poller.cleanupSem"));
 }
开发者ID:rickb838,项目名称:scalr,代码行数:7,代码来源:Poller.php

示例2: provideMutexFactories

 /**
  * Provides Mutex factories.
  *
  * @return callable[][] The mutex factories.
  */
 public function provideMutexFactories()
 {
     $cases = ["NoMutex" => [function () {
         return new NoMutex();
     }], "TransactionalMutex" => [function () {
         $pdo = new \PDO("sqlite::memory:");
         $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         return new TransactionalMutex($pdo);
     }], "FlockMutex" => [function () {
         vfsStream::setup("test");
         return new FlockMutex(fopen(vfsStream::url("test/lock"), "w"));
     }], "SemaphoreMutex" => [function () {
         return new SemaphoreMutex(sem_get(ftok(__FILE__, "a")));
     }], "SpinlockMutex" => [function () {
         $mock = $this->getMockForAbstractClass(SpinlockMutex::class, ["test"]);
         $mock->expects($this->any())->method("acquire")->willReturn(true);
         $mock->expects($this->any())->method("release")->willReturn(true);
         return $mock;
     }], "LockMutex" => [function () {
         $mock = $this->getMockForAbstractClass(LockMutex::class);
         $mock->expects($this->any())->method("lock")->willReturn(true);
         $mock->expects($this->any())->method("unlock")->willReturn(true);
         return $mock;
     }]];
     if (getenv("MEMCACHE_HOST")) {
         $cases["MemcacheMutex"] = [function () {
             $memcache = new Memcache();
             $memcache->connect(getenv("MEMCACHE_HOST"));
             return new MemcacheMutex("test", $memcache);
         }];
         $cases["MemcachedMutex"] = [function () {
             $memcache = new Memcached();
             $memcache->addServer(getenv("MEMCACHE_HOST"), 11211);
             return new MemcachedMutex("test", $memcache);
         }];
     }
     if (getenv("REDIS_URIS")) {
         $uris = explode(",", getenv("REDIS_URIS"));
         $cases["PredisMutex"] = [function () use($uris) {
             $clients = array_map(function ($uri) {
                 return new Client($uri);
             }, $uris);
             return new PredisMutex($clients, "test");
         }];
         $cases["PHPRedisMutex"] = [function () use($uris) {
             $apis = array_map(function ($uri) {
                 $redis = new Redis();
                 $uri = parse_url($uri);
                 if (!empty($uri["port"])) {
                     $redis->connect($uri["host"], $uri["port"]);
                 } else {
                     $redis->connect($uri["host"]);
                 }
                 return $redis;
             }, $uris);
             return new PHPRedisMutex($apis, "test");
         }];
     }
     return $cases;
 }
开发者ID:hyperunknown,项目名称:lock,代码行数:65,代码来源:MutexTest.php

示例3: testfailRemovingSemaphore

 /**
  * Tests removing semaphore fails.
  *
  * @test
  * @expectedException bandwidthThrottle\tokenBucket\storage\StorageException
  * @expectedExceptionMessage Could not remove semaphore.
  */
 public function testfailRemovingSemaphore()
 {
     $key = ftok(__FILE__, "a");
     $storage = new IPCStorage($key);
     sem_remove(sem_get($key));
     @$storage->remove();
 }
开发者ID:bandwidth-throttle,项目名称:token-bucket,代码行数:14,代码来源:IPCStorageTest.php

示例4: __construct

 public function __construct($key)
 {
     if (!is_long($key)) {
         E("传入了非法的信号量key");
     }
     $this->ipc_signal = sem_get($key);
 }
开发者ID:yangjian102621,项目名称:herosphp,代码行数:7,代码来源:SemSynLock.class.php

示例5: getSemFd

 /**
  * 获得SemFd
  */
 protected static function getSemFd()
 {
     if (!self::$semFd && extension_loaded('sysvsem')) {
         self::$semFd = sem_get(self::SEM_KEY);
     }
     return self::$semFd;
 }
开发者ID:bennysuh,项目名称:workerman-game,代码行数:10,代码来源:Mutex.php

示例6: getSemaphoreId

 private function getSemaphoreId()
 {
     if ($this->semaphoreId === null) {
         $this->semaphoreId = sem_get($this->key);
     }
     return $this->semaphoreId;
 }
开发者ID:jost125,项目名称:koala-parallel,代码行数:7,代码来源:BinarySemaphore.php

示例7: __construct

 /**
  * @param $config
  * @key string [name]
  * @key string [key]
  * @key array [items]
  */
 function __construct($config)
 {
     $this->logger = Logger::getLogger(__CLASS__);
     $this->initialConfig = $config;
     $this->shm = new Scalr_System_Ipc_Shm($config);
     $key = $this->shm->key + 8;
     $this->logger->debug(sprintf("Get semaphore (key: 0x%08x)", $key));
     $this->sem = sem_get($key, 1, 0666, true);
     if (!$this->sem) {
         throw new Scalr_System_Ipc_Exception("Cannot sem_get (key: {$key})");
     }
     if (!sem_acquire($this->sem)) {
         throw new Scalr_System_Ipc_Exception("Cannot acquire semaphore");
     }
     try {
         $meta = $this->getMeta();
         if ($meta === null) {
             $this->clear0();
         }
         sem_release($this->sem);
     } catch (Exception $e) {
         sem_release($this->sem);
         throw $e;
     }
     if ($config["items"]) {
         foreach ($config["items"] as $item) {
             $this->add($item);
         }
     }
 }
开发者ID:sacredwebsite,项目名称:scalr,代码行数:36,代码来源:ShmSet.php

示例8: __wakeup

 /**
  * Wake up from a sleep
  */
 function __wakeup()
 {
     $this->id = sem_get($this->key);
     shm_attach($this->id);
     $this->refreshMemoryVarList();
     shm_put_var($this->id, 1, shm_get_var($this->id, 1) + 1);
 }
开发者ID:hiveclick,项目名称:mojavi,代码行数:10,代码来源:SharedMemory.php

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

示例10: registerChildPID

 /**
  * Registers the PID of a child-process
  *
  * @param int The PID
  */
 public function registerChildPID($pid)
 {
     $sem_key = sem_get($this->crawler_uniqid);
     sem_acquire($sem_key);
     file_put_contents($this->working_directory . "pids", $pid . "\n", FILE_APPEND);
     sem_release($sem_key);
 }
开发者ID:haythameyd,项目名称:socialfp,代码行数:12,代码来源:PHPCrawlerProcessHandler.class.php

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

示例12: put

 public static function put($killID, $raw)
 {
     $file = static::getFile($killID, true);
     $sem = sem_get(5632);
     // kmdb is 5632 on a phone
     if (!sem_acquire($sem)) {
         throw new Exception('Unable to obtain kmdb semaphore');
     }
     // Thread safe from here until sem_release
     if (!file_exists($file)) {
         $kills = array();
     } else {
         $contents = file_get_contents($file);
         $deflated = gzdecode($contents);
         $kills = unserialize($deflated);
         $contents = null;
     }
     if (!isset($kills["{$killID}"])) {
         $kills["{$killID}"] = $raw;
         $contents = serialize($kills);
         $compressed = gzencode($contents);
         file_put_contents($file, $compressed, LOCK_EX);
     }
     sem_release($sem);
 }
开发者ID:Nord001,项目名称:zKillboard,代码行数:25,代码来源:Killmail.php

示例13: __construct

 public function __construct($path, $currentArticleFile, $debug_delete_file)
 {
     $this->path = $path;
     $this->debug_delete_file = $debug_delete_file;
     $this->currentArticleFile = $currentArticleFile;
     $this->semaphoreID = sem_get(OAIRECORDFILES);
 }
开发者ID:ljarray,项目名称:dbpedia,代码行数:7,代码来源:LiveUpdateIterator.php

示例14: __construct

 /**
  *	Constructor.
  *
  *	@see	BasicMutex::__construct()
  */
 public function __construct($name)
 {
     $this->key = abs(crc32($name));
     $this->sem = sem_get($this->key, 1, 0666, 1);
     if ($this->sem === false) {
         throw new MutexException('Error geting semaphore');
     }
 }
开发者ID:vladikius,项目名称:tephlon,代码行数:13,代码来源:SemaphoreMutex.class.php

示例15: initializeShm

 protected function initializeShm()
 {
     if (null !== $this->shmHandle) {
         return;
     }
     $this->shmHandle = shm_attach($this->getId(), 60 * 1024);
     $this->semHandle = sem_get($this->getId());
 }
开发者ID:emente,项目名称:kataii---kata-framework-2.x,代码行数:8,代码来源:event.php


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