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


PHP shmop_write函数代码示例

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


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

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

示例2: shm_put

function shm_put($shm, $data)
{
    if (!$shm) {
        return false;
    }
    return shmop_write($shm, serialize($data), 0);
}
开发者ID:n2i,项目名称:xvnkb,代码行数:7,代码来源:shmctrl.php

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

示例4: write

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

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

示例6: call

 /**
  * Run some code in a thread.
  *
  * @param callable $func The function to execute
  * @param array|mixed $args The arguments (or a single argument) to pass to the function
  *
  * @return int The pid of the thread created to execute this code
  */
 public function call(callable $func, $args = null)
 {
     $pid = pcntl_fork();
     if ($pid == -1) {
         throw new \Exception("Failed to fork");
     }
     # If this is the child process, then run the requested function
     if (!$pid) {
         try {
             if ($args === null) {
                 $func();
             } else {
                 call_user_func_array($func, $args);
             }
         } catch (\Exception $e) {
             $memory = shmop_open($this->memoryKey, "c", 0644, static::SHARED_MEMORY_LIMIT);
             $errors = shmop_read($memory, 0, static::SHARED_MEMORY_LIMIT);
             $errors = trim($errors);
             if ($errors) {
                 $errors .= "\n";
             }
             $errors .= "Exception: " . $e->getMessage() . " (" . $e->getFile() . ":" . $e->getLine() . ")";
             shmop_write($memory, $errors, 0);
             shmop_close($memory);
             exit(1);
         }
         # Then we must exit or else we will end up the child process running the parent processes code
         die;
     }
     $this->threads[$pid] = $pid;
     return $pid;
 }
开发者ID:duvanskiy,项目名称:yii2-deferred-tasks,代码行数:40,代码来源:Fork.php

示例7: Write

 private function Write($data)
 {
     $tmp = serialize($data);
     $this->ShmIsClean = false;
     //echo "writing $tmp<br/>";
     return shmop_write($this->mShmId, $tmp, 0) == strlen($tmp) ? true : false;
 }
开发者ID:rifkiferdian,项目名称:gtfw_boostab,代码行数:7,代码来源:SharedMemory.class.php

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

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

示例10: unlock

 /**
  * Unlock process
  *
  * @return Mage_Index_Model_Process
  */
 public function unlock()
 {
     $shmId = shmop_open($this->getIndexerId(), 'w', self::PERM, self::LEN);
     shmop_write($shmId, str_repeat('0', $this->_getMicrotimeLen()), 0);
     // cannot delete because sometimes we're not the owner. so overwrite
     shmop_close($shmId);
     $this->_isLocked = false;
 }
开发者ID:ThomasNegeli,项目名称:Magento-FastIndexer,代码行数:13,代码来源:Shmop.php

示例11: addException

 /**
  * Add an exception the shared memory.
  *
  * @param \Throwable $exception The exception instance to add
  *
  * @return void
  */
 public function addException(\Throwable $exception)
 {
     $memory = shmop_open($this->key, "c", 0644, self::LIMIT);
     $exceptions = $this->unserialize($memory);
     $exceptions[] = get_class($exception) . ": " . $exception->getMessage() . " (" . $exception->getFile() . ":" . $exception->getLine() . ")";
     $data = serialize($exceptions);
     shmop_write($memory, $data, 0);
     shmop_close($memory);
 }
开发者ID:duncan3dc,项目名称:fork-helper,代码行数:16,代码来源:SharedMemory.php

示例12: delete

 /**
  * Mark a shared memory block for deletion.
  *
  * @return bool
  */
 public function delete()
 {
     /*
      * Bug fix
      * @link https://bugs.php.net/bug.php?id=71921
      */
     shmop_write($this->shmid, str_pad('', shmop_size($this->shmid), ' '), 0);
     return shmop_delete($this->shmid);
 }
开发者ID:anime-db,项目名称:shmop,代码行数:14,代码来源:FixedBlock.php

示例13: MonWrite

 function MonWrite($data)
 {
     // Escritura de una cadena de texto de prueba en la memoria compartida
     $shm_bytes_written = shmop_write($this->{$shm_id}, $data, 0);
     if ($shm_bytes_written != strlen($data)) {
         debug("No se pudieron escribir todos los datos indicados\n", "red");
     } else {
         debug("Saved {$data}\n", "magenta");
     }
 }
开发者ID:BackupTheBerlios,项目名称:ascore,代码行数:10,代码来源:lib_monitor.php

示例14: set

 function set($key, $val, $ttl = 600)
 {
     if (function_exists('gzcompress')) {
         $val = gzcompress($val, 3);
     }
     $this->shmop_key = ftok($this->pre . $key);
     $this->shmop_id = shmop_open($this->shmop_key, 'c', 0644, strlen($val));
     $result = shmop_write($this->shmop_id, $val, 0);
     shmop_close($this->shmop_id);
     return $result;
 }
开发者ID:hcd2008,项目名称:destoon,代码行数:11,代码来源:cache_shmop.class.php

示例15: write

 public function write($id, $size, $data)
 {
     $shm = $this->open($id, $size);
     $written = shmop_write($shm, $data, 0);
     $this->close($shm);
     if ($written != strlen($data)) {
         trigger_error('pc_Shm: could not write entire length of data', E_USER_ERROR);
         return false;
     }
     return true;
 }
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:11,代码来源:pcshm.php


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