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


PHP shmop_open函数代码示例

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


在下文中一共展示了shmop_open函数的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: __construct

 private function __construct()
 {
     /* if wndows */
     /*
     function ftok($pathname, $proj_id) {
        $st = @stat($pathname);
        if (!$st) {
           return -1;
        }
     
        $key = sprintf("%u", (($st['ino'] & 0xffff) | (($st['dev'] & 0xff) << 16) | (($proj_id & 0xff) << 24)));
        return $key;
     */
     $shm_key = ftok(__FILE__, 't');
     $this->mShmId = shmop_open($shm_key, 'ac', 0, 0);
     if ($this->mShmId) {
         #it is already created
         //echo '#it is already created';
     } else {
         #you need to create it with shmop_open using "c" only
         //echo '#you need to create it with shmop_open using "c" only';
         $this->mShmId = shmop_open($shm_key, 'c', $this->_SHM_AC_, $this->_SHM_SIZE_);
     }
     $this->mShmId = shmop_open($shm_key, 'w', 0, 0);
     //echo 'ShmId:'.$this->mShmId;
     $this->ShmIsClean = false;
 }
开发者ID:rifkiferdian,项目名称:gtfw_boostab,代码行数:27,代码来源:SharedMemory.class.php

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

示例4: save

 public function save($shmKey, $appVars)
 {
     $memBlobkId = @shmop_open($shmKey, "w", 0644, 1024);
     $result = shmop_write($memBlobkId, serialize($appVars), 0);
     shmop_close($memBlobkId);
     return $result;
 }
开发者ID:chathura86,项目名称:zf2-application-variable,代码行数:7,代码来源:Memory.php

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

示例6: alloc

 /**
  * Memory alloc
  */
 protected function alloc()
 {
     if (null !== $this->memory) {
         return;
     }
     $this->memory = shmop_open(ftok(__FILE__, $this->identifier), "c", 0644, $this->segmentSize);
 }
开发者ID:cityware,项目名称:city-shared-memory,代码行数:10,代码来源:Segment.php

示例7: init

 public function init()
 {
     $project = chr(getmypid() % 26 + 65);
     $dir = Yii::getPathOfAlias('application.runtime.cache');
     if (!is_dir($dir)) {
         mkdir($dir);
     }
     $this->fileName = $dir . DIRECTORY_SEPARATOR . 'cache_' . $project . ".dump";
     try {
         $shmKey = ftok(__FILE__, $project);
         if ($shmKey < 0) {
             throw new CException('Bad ftok');
         }
         $this->shmId = @shmop_open($shmKey, "c", 0644, $this->maxSize);
         if ($this->shmId == 0) {
             throw new CException('Bad shmop');
         }
         $try = @unserialize(shmop_read($this->shmId, 0, 0));
         $this->offsetWrite = (int) $try;
         if ($this->offsetWrite == 0) {
             $this->saveOffsetWrite(true);
         } else {
             $this->detectStart();
         }
     } catch (Exception $e) {
         Yii::log('Unable to init shared memory', CLogger::LEVEL_ERROR, 'sharedMemory');
     }
 }
开发者ID:niranjan2m,项目名称:Voyanga,代码行数:28,代码来源:SharedMemory.php

示例8: rm

 function rm($key)
 {
     $this->shmop_key = ftok($this->pre . $key);
     $this->shmop_id = shmop_open($this->shmop_key, 'c', 0644, 0);
     $result = shmop_delete($this->shmop_id);
     shmop_close($this->shmop_id);
     return $result;
 }
开发者ID:hcd2008,项目名称:destoon,代码行数:8,代码来源:cache_shmop.class.php

示例9: getExceptions

 /**
  * Get all the exceptions added to the shared memory.
  *
  * @return \Throwable[]
  */
 public function getExceptions() : array
 {
     $memory = shmop_open($this->key, "a", 0, 0);
     $exceptions = $this->unserialize($memory);
     shmop_delete($memory);
     shmop_close($memory);
     return $exceptions;
 }
开发者ID:duncan3dc,项目名称:fork-helper,代码行数:13,代码来源:SharedMemory.php

示例10: writeValueToSHM

 /**
  * 写入一个值到某shmkey对应的内存块
  *
  * @param int $shmKey 内存块标示key
  * @param string $value 值(必须是字符串,在外部序列化或者encode)
  */
 private function writeValueToSHM($shmKey, $value)
 {
     $data = $value;
     $size = mb_strlen($data, 'UTF-8');
     $shmId = shmop_open($shmKey, 'c', 0644, $size);
     shmop_write($shmId, $data, 0);
     shmop_close($shmId);
 }
开发者ID:shushenghong,项目名称:asphp,代码行数:14,代码来源:SHMCache.php

示例11: open

 /**
  * @param config
  * $systemId = 864;
  * $mode = "c"; // Access mode
  * $permissions = 0755; // Permissions for the shared memory segment
  * $size = 1024; // Size, in bytes, of the segment
  * $shmid = shmop_open($systemid, $mode, $permissions, $size);
  */
 private function open($config)
 {
     $shmid = shmop_open($config['systemId'], $config['mode'], $config['permissions'], $config['size']);
     if ($shmid) {
         return $shmid;
     } else {
         throw new PiiExcepiton('apply for share memory failed');
     }
 }
开发者ID:pengshizhong,项目名称:pii,代码行数:17,代码来源:ShareMemory.php

示例12: setupSegment

 private function setupSegment()
 {
     $id = ftok($this->file, 't');
     if ($id === -1) {
         throw new Exception('could not creating semaphore segment (ftok)');
     }
     $this->id = $id;
     $this->sid = shmop_open($id, 'c', 0644, 100);
 }
开发者ID:nowelium,项目名称:php-thread-utils,代码行数:9,代码来源:Segment.class.php

示例13: MonInit

 function MonInit()
 {
     $this->{$shm_id} = shmop_open(0xff3, "c", 0644, 1024);
     if (!$this->{$shm_id}) {
         debug("No se pudo crear el segmento de memoria compartida\n", "red");
     }
     // Obtencion del tama&ntilde;o del segmento de memoria compartida
     $shm_size = shmop_size($this->{$shm_id});
     debug("Segmento de memoria: se han reservado " . $shm_size . " bytes.\n", "blue");
 }
开发者ID:BackupTheBerlios,项目名称:ascore,代码行数:10,代码来源:lib_monitor.php

示例14: open

 protected function open($id, $size)
 {
     $key = $this->getKey($id);
     $shm = shmop_open($key, 'c', 0644, $size);
     if (!$shm) {
         trigger_error('pc_Shm: could not create shared memory segment', E_USER_ERROR);
         return false;
     }
     return $shm;
 }
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:10,代码来源:pcshm.php

示例15: delete

 /**
  * @return boolean
  */
 public function delete() : bool
 {
     if (!$this->exists()) {
         return true;
     }
     $shmId = @shmop_open($this->shmKey, 'w', 0, 0);
     $result = (bool) @shmop_delete($shmId);
     @shmop_close($shmId);
     return $result;
 }
开发者ID:sgc-fireball,项目名称:libphp,代码行数:13,代码来源:SHM.php


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