本文整理汇总了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);
}
示例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;
}
示例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));
}
}
示例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']);
}
示例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;
}
}
示例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']);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}