本文整理匯總了PHP中shmop_size函數的典型用法代碼示例。如果您正苦於以下問題:PHP shmop_size函數的具體用法?PHP shmop_size怎麽用?PHP shmop_size使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了shmop_size函數的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: size
public function size()
{
if (null === $this->shmSize) {
$this->shmSize = shmop_size($this->shmID);
}
return $this->shmSize;
}
示例3: size
public function size()
{
if ($this->status == self::STATUS_OPENED) {
return shmop_size($this->shmId);
}
return 0;
}
示例4: 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;
}
}
示例5: 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);
}
示例6: 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ñ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");
}
示例7: getCallbackParams
public function getCallbackParams()
{
$shmId = @shmop_open($this->pid, 'a', 0644, 0);
if (empty($shmId)) {
return false;
}
$datas = unserialize(shmop_read($shmId, 0, shmop_size($shmId)));
shmop_delete($shmId);
shmop_close($shmId);
return $datas;
}
示例8: get
function get($key)
{
$this->shmop_key = ftok($this->pre . $key);
//Linux/Unix Only
$this->shmop_id = shmop_open($this->shmop_key, 'c', 0644, 0);
if ($this->shmop_id === false) {
return false;
}
$data = shmop_read($this->shmop_id, 0, shmop_size($this->shmop_id));
shmop_close($this->shmop_id);
return function_exists('gzuncompress') ? gzuncompress($data) : $data;
}
示例9: __destruct
public function __destruct()
{
if ($this->changed) {
$serialized = serialize($this->data);
if (strlen($serialized) > shmop_size($this->res)) {
shmop_delete($this->res);
$this->res = shmop_open($id, 'c', 0644, ceil(strlen($serialized) * 1.25));
}
shmop_write($this->res, $serialized, 0);
}
shmop_close($this->res);
}
示例10: deletemem
public function deletemem($shmkey)
{
$size = shmop_size($shmkey);
if ($size > 0) {
$this->updatestats($size, "del");
}
if (!shmop_delete($shmkey)) {
shmop_close($shmkey);
return false;
} else {
shmop_close($shmkey);
return true;
}
}
示例11: stream_read
function stream_read($count)
{
if ($this->body === NULL) {
$this->id = ftok($this->path, 'M');
$shm = @shmop_open($this->id, 'a', 0, 0);
if ($shm) {
$this->body = shmop_read($shm, 0, shmop_size($shm));
} else {
$this->body = file_get_contents($this->path);
}
}
$ret = substr($this->body, $this->position, $count);
$this->position += strlen($ret);
return $ret;
}
示例12: __destruct
public function __destruct()
{
if ($this->db) {
$last = STORAGE_PATH . DS . 'memory' . sha1($this->ns . $this->entity) . '.last';
$size = STORAGE_PATH . DS . 'memory' . sha1($this->ns . $this->entity) . '.dbsize';
$age = time() - filemtime($last);
if ($age >= 900) {
File::delete($last);
File::create($last);
$this->write();
}
File::delete($size);
File::put($size, shmop_size($this->db));
shmop_close($this->db);
}
}
示例13: readAndDelete
/**
* read data and delete shared memory
*
* @return mix
* @throws RuntimeException
*/
public function readAndDelete()
{
$s = shmop_open($this->genKey(), 'a', 0, 0);
if ($s === false) {
throw new RuntimeException('could not open shared memory');
}
$data = shmop_read($s, 0, shmop_size($s));
shmop_close($s);
try {
$this->delete();
} catch (RuntimeException $e) {
throw $e;
}
$unserialized = unserialize($data);
return $unserialized['data'];
}
示例14: read
/**
* @todo fix mixed return types!
* @return string|null
*/
public function read()
{
if (!$this->exists()) {
return null;
}
$shmId = @shmop_open($this->shmKey, 'w', 0, 0);
if (!$shmId) {
return null;
}
$size = @shmop_size($shmId);
if (!$size) {
return null;
}
$data = @shmop_read($shmId, 0, $size);
@shmop_close($shmId);
return (string) $data;
}
示例15: isLocked
/**
* Check if process is locked
*
* @return bool
*/
public function isLocked()
{
if (0 === $this->getIndexerId()) {
Mage::throwException('FastIndexer: IndexerId cannot be 0');
}
if (null !== $this->_isLocked) {
return $this->_isLocked;
}
$shmId = @shmop_open($this->getIndexerId(), 'a', self::PERM, self::LEN);
if (false === $shmId) {
$this->_isLocked = false;
return $this->_isLocked;
}
$size = shmop_size($shmId);
$startTime = shmop_read($shmId, 0, $size);
shmop_close($shmId);
$this->_isLocked = $this->_isLockedByTtl((double) $startTime);
return $this->_isLocked;
}