當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。