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


PHP shmop_read函数代码示例

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


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

示例1: send

 /**
  * Writes a message to the shared memory.
  *
  * @param mixed   $message The message to send
  * @param integer $signal  The signal to send afterward
  * @param integer $pause   The number of microseconds to pause after signalling
  */
 public function send($message, $signal = null, $pause = 500)
 {
     $messageArray = array();
     if (($shmId = @shmop_open($this->pid, 'a', 0, 0)) > 0) {
         // Read any existing messages in shared memory
         $readMessage = shmop_read($shmId, 0, shmop_size($shmId));
         $messageArray[] = unserialize($readMessage);
         shmop_delete($shmId);
         shmop_close($shmId);
     }
     // Add the current message to the end of the array, and serialize it
     $messageArray[] = $message;
     $serializedMessage = serialize($messageArray);
     // Write new serialized message to shared memory
     $shmId = shmop_open($this->pid, 'c', 0644, strlen($serializedMessage));
     if (!$shmId) {
         throw new ProcessControlException(sprintf('Not able to create shared memory segment for PID: %s', $this->pid));
     } else {
         if (shmop_write($shmId, $serializedMessage, 0) !== strlen($serializedMessage)) {
             throw new ProcessControlException(sprintf('Not able to write message to shared memory segment for segment ID: %s', $shmId));
         }
     }
     if (false === $signal) {
         return;
     }
     $this->signal($signal ?: $this->signal);
     usleep($pause);
 }
开发者ID:edwardstock,项目名称:spork,代码行数:35,代码来源:SharedMemory.php

示例2: shm_remove_var

 function shm_remove_var($id, $key)
 {
     global $_shm_size;
     if (($dat = @shmop_read($id, 0, 4)) === false) {
         $dat = array();
     } else {
         $len = unpack('L', $dat);
         $len = array_shift($len);
         $dat = unserialize(shmop_read($id, 4, $len));
     }
     if (isset($dat[$key])) {
         unset($dat[$key]);
     } else {
         return false;
     }
     $dat = serialize($dat);
     $l = strlen($dat);
     if ($l + 4 > $_shm_size) {
         return false;
     }
     $dat = pack('L', strlen($dat)) . $dat;
     if (@shmop_write($id, $dat, 0) !== false) {
         return true;
     }
     return false;
 }
开发者ID:buganini,项目名称:php-snippets,代码行数:26,代码来源:shm.php

示例3: read

 /**
  * This function implements the reading mechanism for a shared memory
  * segment following a specific layout.
  * @param $index position that should be read regarding the layout.
  *               if $index is left -1 then the upcoming parameters will
  *               be used to perform a search otherwise they are used to
  *               perform checks on the elment addressed.
  * @param $skey string key for the element's $kpos'th node
  * @param $kpos $skey position regarding the segment layout
  * @param $val value of the last serialized element stored
  *             if it is a string the type of the objects will be compared
  *             otherwise the obejects will be compared
  * @return trimmed string for the whole contents of the segment if 
  *         $index is -1, if $index is >= 0 and valid the complete 
  *         element at this position, otherwise an empty string
  */
 public function read($index = -1, $skey = "", $kpos = -1, $val = null, $full = true)
 {
     $rs = "";
     $this->log(__METHOD__ . ": idx=%, skey=%, kpos=%, val=%, full=%", array($index, $skey, $kpos, StringUtil::get_object_string($val), $full));
     // reading the whole contents if index is not set and the upcoming
     // parameters either
     if (strncmp(gettype($index), "integer", 7) == 0 && $index == -1 && strncmp(gettype($skey), "string", 6) == 0 && strlen($skey) == 0 && strncmp(gettype($kpos), "integer", 7) == 0 && $kpos == -1) {
         $s = shmop_read($this->element->get_shm_seg_id(), 0, $this->element->get_shm_seg_size());
         if ($s) {
             $rs = trim($s);
         }
         // searching if the index is not set but parameters 2 to 5 are
         // but not with default values
     } else {
         if (strncmp(gettype($index), "integer", 7) == 0 && $index == -1 && strncmp(gettype($skey), "string", 6) == 0 && strlen($skey) > 0 && strncmp(gettype($kpos), "integer", 7) == 0 && $kpos > -1) {
             $rs = $this->search($index, $skey, $kpos, $val, $this->get_search_type());
             // reading an index is a bit more complex
         } else {
             if (strncmp(gettype($index), "integer", 7) == 0 && $index > -1) {
                 $xcontents = $this->get();
                 $xcli = count($xcontents) - 1;
                 // now lets get the requested element if it exist
                 // and complete its layout
                 if ($index <= $xcli) {
                     $rs = trim($xcontents[$index]) . $this->element->get_shm_seg_var_eright() . $this->element->get_shm_seg_var_delimiter();
                 }
             }
         }
     }
     if ($full) {
         return $rs;
     } else {
         return unserialize(substr($rs, strrpos($rs, $this->element->get_shm_seg_var_eleft()) + 1, strlen($rs) - strlen($this->element->get_shm_seg_var_eright() . $this->element->get_shm_seg_var_delimiter()) - strrpos($rs, $this->element->get_shm_seg_var_eleft()) - 1));
     }
 }
开发者ID:marcbredt,项目名称:heili,代码行数:51,代码来源:sharedmemoryreader.class.php

示例4: session_value

function session_value($name, $index)
{
    global $shm_key, $shm_var, $sem_id;
    switch ($index) {
        case 'config':
            $shm_size = 859;
            break;
        case 'ipdata':
            $shm_size = 30050;
            break;
        default:
            $shm_size = 0;
    }
    sem_acquire($sem_id['shlock']);
    $shm_id = shmop_open($shm_key[$index], 'c', 0644, $shm_size);
    if ($name == 'update') {
        $shm_data = serialize($shm_var[$index]);
        shmop_write($shm_id, str_pad($shm_data, $shm_size, "", STR_PAD_RIGHT), 0);
    } else {
        $shm_data = shmop_read($shm_id, 0, $shm_size);
        $shm_var[$index] = @unserialize($shm_data);
    }
    shmop_close($shm_id);
    sem_release($sem_id['shlock']);
}
开发者ID:phateio,项目名称:php-radio-kernel,代码行数:25,代码来源:shmop.inc.php

示例5: get

 /**
  * 读取缓存
  * 
  * @access public
  * @param string $name
  *            缓存变量名
  * @return mixed
  */
 public function get($name = false)
 {
     N('cache_read', 1);
     $id = shmop_open($this->handler, 'c', 0600, 0);
     if ($id !== false) {
         $ret = unserialize(shmop_read($id, 0, shmop_size($id)));
         shmop_close($id);
         if ($name === false) {
             return $ret;
         }
         $name = $this->options['prefix'] . $name;
         if (isset($ret[$name])) {
             $content = $ret[$name];
             if (C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) {
                 // 启用数据压缩
                 $content = gzuncompress($content);
             }
             return $content;
         } else {
             return null;
         }
     } else {
         return false;
     }
 }
开发者ID:siimanager,项目名称:sii,代码行数:33,代码来源:Shmop.class.php

示例6: read

 /**
  * @param $key
  * @param int $mode
  * @param int $size
  * @return mixed|null
  * @throws OpenSharedMemoryException
  * @throws ReadSharedMemoryException
  * @throws SupportSharedMemoryException
  */
 public static function read($key, $mode = 0644, $size = 100)
 {
     if (!self::checkSHMOPSupport()) {
         return null;
     }
     @($shm_id = shmop_open($key, "a", $mode, $size));
     //read only
     if (!$shm_id) {
         throw new OpenSharedMemoryException("The shared memory block could not be opened");
     }
     @($cached_string = shmop_read($shm_id, 0, $size));
     if (!$cached_string) {
         shmop_delete($shm_id);
         shmop_close($shm_id);
         throw new ReadSharedMemoryException("The shared memory block could not be read");
     }
     $data = json_decode($cached_string, true);
     if (isset($data['expiration']) && time() > $data['expiration'] || !isset($data['expiration'])) {
         shmop_delete($shm_id);
         shmop_close($shm_id);
         return null;
     }
     shmop_close($shm_id);
     return unserialize($data['value']);
 }
开发者ID:splitio,项目名称:php-client,代码行数:34,代码来源:SharedMemory.php

示例7: read

 public function read()
 {
     if (!empty($this->id) && !isset($this->shmSize)) {
         $header = shmop_read($this->id, 0, 16);
         $aHeader = unpack('lcrcHeader/lshmSize/ldataSize/lcrcData', $header);
         $crcHeader = crc32(substr($header, 1));
         $crcHeader = 0;
         if ($crcHeader == $aHeader['crcHeader']) {
             $this->shmSize = $aHeader['shmSize'];
             if ($aHeader['dataSize'] > 0) {
                 $data = shmop_read($this->id, 16, $aHeader['dataSize']);
                 $crcData = crc32($data);
                 $crcData = 0;
                 if ($crcData == $aHeader['crcData']) {
                     $this->aBucket = unserialize($data);
                     return true;
                 }
             }
         } else {
             // Damaged!
             $this->recreate();
         }
     }
     return false;
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:25,代码来源:ShmBucket.php

示例8: readShared

 public function readShared()
 {
     sem_acquire($this->sem_id);
     $data = shmop_read($this->shm_id, 0, $this->size);
     $data = trim($data);
     $data = unserialize($data);
     return $data;
 }
开发者ID:hduwzy,项目名称:multi_process,代码行数:8,代码来源:Shm.php

示例9: read

 public function read($length = 0, $from = 0)
 {
     $data = null;
     if ($this->status == self::STATUS_OPENED) {
         $data = shmop_read($this->shmId, $from, $length);
     }
     return $data;
 }
开发者ID:dan-homorodean,项目名称:falx-concurrency-and-ipc,代码行数:8,代码来源:Handle.php

示例10: read

 public function read($start, $length = null)
 {
     $offset = $start >= 0 ? $start : $this->shmSize + $start;
     if (null === $length) {
         $length = $start >= 0 ? $this->shmSize - $start : -$start;
     }
     return shmop_read($this->shmID, $offset, $length);
 }
开发者ID:panlatent,项目名称:easy-shm,代码行数:8,代码来源:Shm.php

示例11: MonRead

 function MonRead()
 {
     $my_string = shmop_read($this->{$shm_id}, 0, $shm_size);
     if (!$my_string) {
         debug("No se pudo leer el segmento de memoria compartida\n", "red");
     }
     return $my_string;
 }
开发者ID:BackupTheBerlios,项目名称:ascore,代码行数:8,代码来源:lib_monitor.php

示例12: shm_get

function shm_get($shm)
{
    if (!$shm) {
        return array();
    }
    $data = shmop_read($shm, 0, SFC_SHM_DATASIZE);
    return $data === false ? array() : unserialize($data);
}
开发者ID:n2i,项目名称:xvnkb,代码行数:8,代码来源:shmctrl.php

示例13: unserialize

 /**
  * Get the exception details out of shared memory.
  *
  * @param resource $memory The shmop resource from shmop_open()
  *
  * @return \Throwable[]
  */
 private function unserialize($memory) : array
 {
     $data = shmop_read($memory, 0, self::LIMIT);
     $exceptions = unserialize($data);
     if (!is_array($exceptions)) {
         $exceptions = [];
     }
     return $exceptions;
 }
开发者ID:duncan3dc,项目名称:fork-helper,代码行数:16,代码来源:SharedMemory.php

示例14: deQueue

 public function deQueue()
 {
     if ($this->front == $this->rear) {
         // 队空
         return false;
     }
     $value = shmop_read($this->shmId, $this->front, $this->blockSize - 1);
     $this->front = $this->ptrInc($this->front);
     return $this->decode($value);
 }
开发者ID:shampeak,项目名称:_m.so,代码行数:10,代码来源:___SHMQueue.php

示例15: wait

 protected function wait(Thread $job)
 {
     while (true) {
         $data = shmop_read($job->sid, 0, 1);
         if (strcmp($data, self::UNLOCK) === 0) {
             break;
         }
         $this->sleep(1);
     }
 }
开发者ID:nowelium,项目名称:php-thread-utils,代码行数:10,代码来源:Thread.class.php


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