本文整理汇总了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;
}
示例2: shm_put
function shm_put($shm, $data)
{
if (!$shm) {
return false;
}
return shmop_write($shm, serialize($data), 0);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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']);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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");
}
}
示例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;
}
示例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;
}