當前位置: 首頁>>代碼示例>>PHP>>正文


PHP shm_attach函數代碼示例

本文整理匯總了PHP中shm_attach函數的典型用法代碼示例。如果您正苦於以下問題:PHP shm_attach函數的具體用法?PHP shm_attach怎麽用?PHP shm_attach使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了shm_attach函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

示例2: alloc

 /**
  * Memory alloc
  */
 protected function alloc()
 {
     if (null !== $this->memory) {
         return;
     }
     $this->memory = shm_attach(ftok(__FILE__, $this->identifier), $this->segmentSize, 0644);
 }
開發者ID:cityware,項目名稱:city-shared-memory,代碼行數:10,代碼來源:Bloc.php

示例3: __construct

 public function __construct(string $namespace = null)
 {
     if (is_null($namespace)) {
         $namespace = isset($_SERVER['PWD']) ? $_SERVER['PWD'] : 'SHM';
     }
     $this->_shmid = shm_attach(crc32($namespace));
 }
開發者ID:boyxp,項目名稱:bluefin-base,代碼行數:7,代碼來源:shm.php

示例4: flush

 /**
  * Flush entire cache.
  */
 function flush()
 {
     parent::flush();
     // remove and reconnect to the SHM block
     shm_remove($this->shmid);
     $this->shmid = shm_attach($this->shmkey, $this->memsize, 0600);
 }
開發者ID:jvinet,項目名稱:pronto,代碼行數:10,代碼來源:shm.php

示例5: __construct

 /**
  * @param int $id
  * @param Lock $lock
  */
 public function __construct($id, LockInterface $lock)
 {
     $this->id = $id;
     $this->lock = $lock;
     $this->memory = shm_attach($this->id);
     $this->updateNbProcess(+1);
 }
開發者ID:CrakLabs,項目名稱:ipc-component,代碼行數:11,代碼來源:ShmMemory.php

示例6: __construct

 public function __construct()
 {
     if (!function_exists('shm_attach')) {
         throw new \RuntimeException('You need to enabled Shared Memory System V(see more "Semaphore")');
     }
     $this->shared_memory_segment = shm_attach(time() + rand(1, 1000));
 }
開發者ID:vatson,項目名稱:isolated-callback,代碼行數:7,代碼來源:SharedMemory.php

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

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

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

示例10: open

 public function open()
 {
     $this->shm = shm_attach($this->ipckey, 256000, 0666);
     if (!$this->shm) {
         throw new \Exception("Could not open shared memory segment");
     }
 }
開發者ID:noccy80,項目名稱:cherryphp,代碼行數:7,代碼來源:ipcsharedobject.php

示例11: __construct

 private function __construct()
 {
     $this->id = @shm_attach(55, 10000, 0600);
     if (!$this->id) {
         throw new \Exception('Нет доступа к общей памяти');
     }
 }
開發者ID:pers1307,項目名稱:levelUpPHP,代碼行數:7,代碼來源:MemApplicationRegistry.php

示例12: attach

 /**
  * Create shared memory block
  */
 private function attach()
 {
     $this->__key = ftok($this->__path, $this->__proj_id);
     $this->__shm = shm_attach($this->__key, $this->__size);
     //allocate shared memory
     $this->__mutex = sem_get($this->__key, 1);
     //create mutex with same key
 }
開發者ID:nejtr0n,項目名稱:shmestage,代碼行數:11,代碼來源:SharedMemory.php

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

示例14: open

 public function open()
 {
     $perms = $this->config['shared_memory.permissions'];
     $size = $this->config['rabbitmq.max_workers'] * 44;
     $file = $this->tmp_file;
     $this->shm_res = shm_attach(ftok($file, 'L'), $size, $perms);
     $this->logger->debug('Opening shared memory resource with id: [' . intval($this->shm_res) . '] on file [' . $this->tmp_file . ']');
 }
開發者ID:brutalsys,項目名稱:rmq_worker,代碼行數:8,代碼來源:SHM.php

示例15: pleac_Sharing_Variables_in_Different_Processes

function pleac_Sharing_Variables_in_Different_Processes()
{
    // sharetest - test shared variables across forks
    $SHM_KEY = ftok(__FILE__, chr(1));
    $handle = sem_get($SHM_KEY);
    $buffer = shm_attach($handle, 1024);
    // The original recipe has an INT signal handler here. However, it
    // causes erratic behavior with PHP, and PHP seems to do the right
    // thing without it.
    for ($i = 0; $i < 10; $i++) {
        $child = pcntl_fork();
        if ($child == -1) {
            die('cannot fork');
        } elseif ($child) {
            $kids[] = $child;
            // in case we care about their pids
        } else {
            squabble();
            exit;
        }
    }
    while (true) {
        print 'Buffer is ' . shm_get_var($buffer, 1) . "\n";
        sleep(1);
    }
    die('Not reached');
    function squabble()
    {
        global $handle;
        global $buffer;
        $i = 0;
        $pid = getmypid();
        while (true) {
            if (preg_match("/^{$pid}\\b/", shm_get_var($buffer, 1))) {
                continue;
            }
            sem_acquire($handle);
            $i++;
            shm_put_var($buffer, 1, "{$pid} {$i}");
            sem_release($handle);
        }
    }
    // Buffer is 14357 1
    // Buffer is 14355 3
    // Buffer is 14355 4
    // Buffer is 14354 5
    // Buffer is 14353 6
    // Buffer is 14351 8
    // Buffer is 14351 9
    // Buffer is 14350 10
    // Buffer is 14348 11
    // Buffer is 14348 12
    // Buffer is 14357 10
    // Buffer is 14357 11
    // Buffer is 14355 13
    // ...
}
開發者ID:Halfnhav4,項目名稱:pfff,代碼行數:57,代碼來源:Sharing_Variables_in_Different_Processes.php


注:本文中的shm_attach函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。