/** * 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); }
public function size() { if (null === $this->shmSize) { $this->shmSize = shmop_size($this->shmID); } return $this->shmSize; }
public function size() { if ($this->status == self::STATUS_OPENED) { return shmop_size($this->shmId); } return 0; }
/** * 读取缓存 * * @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; } }
/** * 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); }
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"); }
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; }
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; }
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); }
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; } }
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; }
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); } }
/** * 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']; }
/** * @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; }
/** * 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; }
function _setup_segments($gi) { $gi->databaseType = GEOIP_COUNTRY_EDITION; $gi->record_length = STANDARD_RECORD_LENGTH; if ($gi->flags & GEOIP_SHARED_MEMORY) { $offset = @shmop_size($gi->shmid) - 3; for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { $delim = @shmop_read($gi->shmid, $offset, 3); $offset += 3; if ($delim == chr(255) . chr(255) . chr(255)) { $gi->databaseType = ord(@shmop_read($gi->shmid, $offset, 1)); $offset++; if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; } else { if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; } else { if ($gi->databaseType == GEOIP_CITY_EDITION_REV0 || $gi->databaseType == GEOIP_CITY_EDITION_REV1 || $gi->databaseType == GEOIP_ORG_EDITION || $gi->databaseType == GEOIP_ISP_EDITION || $gi->databaseType == GEOIP_ASNUM_EDITION) { $gi->databaseSegments = 0; $buf = @shmop_read($gi->shmid, $offset, SEGMENT_RECORD_LENGTH); for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { $gi->databaseSegments += ord($buf[$j]) << $j * 8; } if ($gi->databaseType == GEOIP_ORG_EDITION || $gi->databaseType == GEOIP_ISP_EDITION) { $gi->record_length = ORG_RECORD_LENGTH; } } } } break; } else { $offset -= 4; } } if ($gi->databaseType == GEOIP_COUNTRY_EDITION || $gi->databaseType == GEOIP_PROXY_EDITION || $gi->databaseType == GEOIP_NETSPEED_EDITION) { $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; } } else { $filepos = ftell($gi->filehandle); fseek($gi->filehandle, -3, SEEK_END); for ($i = 0; $i < STRUCTURE_INFO_MAX_SIZE; $i++) { $delim = fread($gi->filehandle, 3); if ($delim == chr(255) . chr(255) . chr(255)) { $gi->databaseType = ord(fread($gi->filehandle, 1)); if ($gi->databaseType == GEOIP_REGION_EDITION_REV0) { $gi->databaseSegments = GEOIP_STATE_BEGIN_REV0; } else { if ($gi->databaseType == GEOIP_REGION_EDITION_REV1) { $gi->databaseSegments = GEOIP_STATE_BEGIN_REV1; } else { if ($gi->databaseType == GEOIP_CITY_EDITION_REV0 || $gi->databaseType == GEOIP_CITY_EDITION_REV1 || $gi->databaseType == GEOIP_ORG_EDITION || $gi->databaseType == GEOIP_ISP_EDITION || $gi->databaseType == GEOIP_ASNUM_EDITION) { $gi->databaseSegments = 0; $buf = fread($gi->filehandle, SEGMENT_RECORD_LENGTH); for ($j = 0; $j < SEGMENT_RECORD_LENGTH; $j++) { $gi->databaseSegments += ord($buf[$j]) << $j * 8; } if ($gi->databaseType == GEOIP_ORG_EDITION || $gi->databaseType == GEOIP_ISP_EDITION) { $gi->record_length = ORG_RECORD_LENGTH; } } } } break; } else { fseek($gi->filehandle, -4, SEEK_CUR); } } if ($gi->databaseType == GEOIP_COUNTRY_EDITION || $gi->databaseType == GEOIP_PROXY_EDITION || $gi->databaseType == GEOIP_NETSPEED_EDITION) { $gi->databaseSegments = GEOIP_COUNTRY_BEGIN; } fseek($gi->filehandle, $filepos, SEEK_SET); } return $gi; }
/** * Parses the database file to determine what kind of database is being used and setup * segment sizes and start points that will be used by the seek*() methods later. * * @return void */ protected function setupSegments() { $this->databaseType = self::COUNTRY_EDITION; $this->recordLength = self::STANDARD_RECORD_LENGTH; if ($this->flags & self::SHARED_MEMORY) { $offset = shmop_size($this->shmid) - 3; for ($i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++) { $delim = shmop_read($this->shmid, $offset, 3); $offset += 3; if ($delim == chr(255) . chr(255) . chr(255)) { $this->databaseType = ord(shmop_read($this->shmid, $offset, 1)); $offset++; if ($this->databaseType === self::REGION_EDITION_REV0) { $this->databaseSegments = self::STATE_BEGIN_REV0; } elseif ($this->databaseType === self::REGION_EDITION_REV1) { $this->databaseSegments = self::STATE_BEGIN_REV1; } elseif ($this->databaseType === self::CITY_EDITION_REV0 || $this->databaseType === self::CITY_EDITION_REV1 || $this->databaseType === self::ORG_EDITION) { $this->databaseSegments = 0; $buf = shmop_read($this->shmid, $offset, self::SEGMENT_RECORD_LENGTH); for ($j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++) { $this->databaseSegments += ord($buf[$j]) << $j * 8; } if ($this->databaseType === self::ORG_EDITION) { $this->recordLength = self::ORG_RECORD_LENGTH; } } break; } else { $offset -= 4; } } if ($this->databaseType == self::COUNTRY_EDITION) { $this->databaseSegments = self::COUNTRY_BEGIN; } } else { $filepos = ftell($this->filehandle); fseek($this->filehandle, -3, SEEK_END); for ($i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++) { $delim = fread($this->filehandle, 3); if ($delim == chr(255) . chr(255) . chr(255)) { $this->databaseType = ord(fread($this->filehandle, 1)); if ($this->databaseType === self::REGION_EDITION_REV0) { $this->databaseSegments = self::STATE_BEGIN_REV0; } elseif ($this->databaseType === self::REGION_EDITION_REV1) { $this->databaseSegments = self::STATE_BEGIN_REV1; } elseif ($this->databaseType === self::CITY_EDITION_REV0 || $this->databaseType === self::CITY_EDITION_REV1 || $this->databaseType === self::ORG_EDITION) { $this->databaseSegments = 0; $buf = fread($this->filehandle, self::SEGMENT_RECORD_LENGTH); for ($j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++) { $this->databaseSegments += ord($buf[$j]) << $j * 8; } if ($this->databaseType === self::ORG_EDITION) { $this->recordLength = self::ORG_RECORD_LENGTH; } } break; } else { fseek($this->filehandle, -4, SEEK_CUR); } } if ($this->databaseType === self::COUNTRY_EDITION) { $this->databaseSegments = self::COUNTRY_BEGIN; } fseek($this->filehandle, $filepos, SEEK_SET); } }
public function _setup_segments() { $this->databaseType = self::GEOIP_COUNTRY_EDITION; $this->record_length = self::STANDARD_RECORD_LENGTH; if ($this->flags & self::GEOIP_SHARED_MEMORY) { $offset = @shmop_size($this->shmid) - 3; for ($i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++) { $delim = @shmop_read($this->shmid, $offset, 3); $offset += 3; if ($delim == chr(255) . chr(255) . chr(255)) { $this->databaseType = ord(@shmop_read($this->shmid, $offset, 1)); $offset++; if ($this->databaseType == self::GEOIP_REGION_EDITION_REV0) { $this->databaseSegments = self::GEOIP_STATE_BEGIN_REV0; } else { if ($this->databaseType == self::GEOIP_REGION_EDITION_REV1) { $this->databaseSegments = self::GEOIP_STATE_BEGIN_REV1; } else { if ($this->databaseType == self::GEOIP_CITY_EDITION_REV0 || $this->databaseType == self::GEOIP_CITY_EDITION_REV1 || $this->databaseType == self::GEOIP_ORG_EDITION || $this->databaseType == self::GEOIP_ORG_EDITION_V6 || $this->databaseType == self::GEOIP_DOMAIN_EDITION || $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 || $this->databaseType == self::GEOIP_ISP_EDITION || $this->databaseType == self::GEOIP_ISP_EDITION_V6 || $this->databaseType == self::GEOIP_USERTYPE_EDITION || $this->databaseType == self::GEOIP_USERTYPE_EDITION_V6 || $this->databaseType == self::GEOIP_LOCATIONA_EDITION || $this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION || $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 || $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 || $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1 || $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6 || $this->databaseType == self::GEOIP_ASNUM_EDITION || $this->databaseType == self::GEOIP_ASNUM_EDITION_V6) { $this->databaseSegments = 0; $buf = @shmop_read($this->shmid, $offset, self::SEGMENT_RECORD_LENGTH); for ($j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++) { $this->databaseSegments += ord($buf[$j]) << $j * 8; } if ($this->databaseType == self::GEOIP_ORG_EDITION || $this->databaseType == self::GEOIP_ORG_EDITION_V6 || $this->databaseType == self::GEOIP_DOMAIN_EDITION || $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 || $this->databaseType == self::GEOIP_ISP_EDITION || $this->databaseType == self::GEOIP_ISP_EDITION_V6) { $this->record_length = self::ORG_RECORD_LENGTH; } } } } break; } else { $offset -= 4; } } if ($this->databaseType == self::GEOIP_COUNTRY_EDITION || $this->databaseType == self::GEOIP_COUNTRY_EDITION_V6 || $this->databaseType == self::GEOIP_PROXY_EDITION || $this->databaseType == self::GEOIP_NETSPEED_EDITION) { $this->databaseSegments = self::GEOIP_COUNTRY_BEGIN; } } else { $filepos = ftell($this->filehandle); fseek($this->filehandle, -3, SEEK_END); for ($i = 0; $i < self::STRUCTURE_INFO_MAX_SIZE; $i++) { $delim = fread($this->filehandle, 3); if ($delim == chr(255) . chr(255) . chr(255)) { $this->databaseType = ord(fread($this->filehandle, 1)); if ($this->databaseType == self::GEOIP_REGION_EDITION_REV0) { $this->databaseSegments = self::GEOIP_STATE_BEGIN_REV0; } else { if ($this->databaseType == self::GEOIP_REGION_EDITION_REV1) { $this->databaseSegments = self::GEOIP_STATE_BEGIN_REV1; } else { if ($this->databaseType == self::GEOIP_CITY_EDITION_REV0 || $this->databaseType == self::GEOIP_CITY_EDITION_REV1 || $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 || $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 || $this->databaseType == self::GEOIP_ORG_EDITION || $this->databaseType == self::GEOIP_DOMAIN_EDITION || $this->databaseType == self::GEOIP_ISP_EDITION || $this->databaseType == self::GEOIP_ORG_EDITION_V6 || $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 || $this->databaseType == self::GEOIP_ISP_EDITION_V6 || $this->databaseType == self::GEOIP_LOCATIONA_EDITION || $this->databaseType == self::GEOIP_ACCURACYRADIUS_EDITION || $this->databaseType == self::GEOIP_CITY_EDITION_REV0_V6 || $this->databaseType == self::GEOIP_CITY_EDITION_REV1_V6 || $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1 || $this->databaseType == self::GEOIP_NETSPEED_EDITION_REV1_V6 || $this->databaseType == self::GEOIP_USERTYPE_EDITION || $this->databaseType == self::GEOIP_USERTYPE_EDITION_V6 || $this->databaseType == self::GEOIP_ASNUM_EDITION || $this->databaseType == self::GEOIP_ASNUM_EDITION_V6) { $this->databaseSegments = 0; $buf = fread($this->filehandle, self::SEGMENT_RECORD_LENGTH); for ($j = 0; $j < self::SEGMENT_RECORD_LENGTH; $j++) { $this->databaseSegments += ord($buf[$j]) << $j * 8; } if ($this->databaseType == self::GEOIP_ORG_EDITION || $this->databaseType == self::GEOIP_DOMAIN_EDITION || $this->databaseType == self::GEOIP_ISP_EDITION || $this->databaseType == self::GEOIP_ORG_EDITION_V6 || $this->databaseType == self::GEOIP_DOMAIN_EDITION_V6 || $this->databaseType == self::GEOIP_ISP_EDITION_V6) { $this->record_length = self::ORG_RECORD_LENGTH; } } } } break; } else { fseek($this->filehandle, -4, SEEK_CUR); } } if ($this->databaseType == self::GEOIP_COUNTRY_EDITION || $this->databaseType == self::GEOIP_COUNTRY_EDITION_V6 || $this->databaseType == self::GEOIP_PROXY_EDITION || $this->databaseType == self::GEOIP_NETSPEED_EDITION) { $this->databaseSegments = self::GEOIP_COUNTRY_BEGIN; } fseek($this->filehandle, $filepos, SEEK_SET); } }
private function _sharedMemRead($start, $maxLength) { $readLength = min(shmop_size($this->shmid) - $start, $maxLength); return shmop_read($this->shmid, $start, $readLength); }
/** * Read data from IPC segment * * @throws ZendX_Console_Process_Exception When writing of SHM segment fails * @return void */ private function _readFromIpcSegment() { $serializedIpcData = shmop_read($this->_internalIpcKey, 0, shmop_size($this->_internalIpcKey)); if ($serializedIpcData === false) { require_once 'ZendX/Console/Process/Exception.php'; throw new ZendX_Console_Process_Exception('Fatal error while reading SHM segment'); } $data = @unserialize($serializedIpcData); if ($data !== false) { $this->_internalIpcData = $data; } }
public function get_stat() { $stat['shm_id'] = $this->shm; $stat['shm_key'] = $this->shmkey; $sem = $this->sem; if (is_a($this->sem, 'MultiAccess')) { /** @var MultiAccess $sem */ $q_read = msg_get_queue($sem->getReadQKey()); if (!empty($q_read)) { $q_stat = msg_stat_queue($q_read); $stat['readers'] = $q_stat['msg_qnum']; $stat['readers_qid'] = $sem->getReadQKey(); } $q_writers = msg_get_queue($sem->getWriteQKey()); if (!empty($q_writers)) { $q_stat = msg_stat_queue($q_writers); $stat['writers'] = $q_stat['msg_qnum']; $stat['writers_qid'] = $sem->getWriteQKey(); } $this->addErrLog($sem->getErrLog()); } $this->readmemory(); $stat['info'] = $this->mem[self::map_info]; $stat['size'] = strlen(serialize($this->mem)); $stat['max_size'] = shmop_size($this->shm); $stat['err_log'] = $this->getErrLog(); return $stat; }
$val_tot = 0; $metnum = 0; if (isset($argv[1])) { $metnum = $argv[1]; } else { die("Usage: {$argv['0']} metnum \n"); } include "../config/config_met{$metnum}.php"; $dir = '/run/shm'; //$memdata = file_get_contents('http://localhost/metern/programs/programtotal.php'); //$memory = json_decode($memdata, true); $memory = array(); //echo "MEMORY = $MEMORY\n"; @($shmid = shmop_open($MEMORY, 'a', 0, 0)); if (!empty($shmid)) { $size = shmop_size($shmid); shmop_close($shmid); $shmid = shmop_open($MEMORY, 'c', 0644, $size); $memdata = shmop_read($shmid, 0, $size); $memory = json_decode($memdata, true); shmop_close($shmid); } //var_dump($memory); $val = $memory["Totalcounter{$metnum}"]; $arr_val = preg_split("/ /", $val); $last_val = (int) ((double) str_replace(",", ".", $arr_val[0]) * 1000); $cmd = 'cat ' . $dir . '/metern' . $metnum . '.txt | egrep "^' . $metnum . '\\(" | grep "*Wh)" | cut -d\\( -f2 | cut -d* -f1'; $meter_val = (int) exec($cmd); # workaround in case of blackout and meter value lesser than previous value if ($meter_val < $last_val && ${'PASSO' . $metnum} - $last_val > 1000) { $val_tot = $last_val;
private function Size() { return shmop_size($this->mShmId); }
<?php $hex_shm_id = 0xff3; $write_d1 = "test #1 of the shmop() extension"; $write_d2 = "test #2 append data to shared memory segment"; echo "shm open for create: "; $shm_id = shmop_open($hex_shm_id, "n", 0644, 1024); if (!$shm_id) { die("failed\n"); } else { echo "ok\n"; } echo "shm size is: " . ($shm_size = shmop_size($shm_id)) . "\n"; echo "shm write test #1: "; $written = shmop_write($shm_id, $write_d1, 0); if ($written != strlen($write_d1)) { echo "failed\n"; } else { echo "ok\n"; } echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n"; shmop_close($shm_id); echo "shm open for read only: "; $shm_id = shmop_open($hex_shm_id, "a", 0644, 1024); if (!$shm_id) { echo "failed\n"; } else { echo "ok\n"; } echo "data in memory is: " . shmop_read($shm_id, 0, $written) . "\n"; /* try to append data to the shared memory segment, this should fail */
/** * returns value of variable in shared mem * * @param mixed $name name of variable or false if all variables needs * * @return mixed PEAR_error or value of the variable * @access public */ function get($name = false) { $id = shmop_open($this->_h, 'c', 0600, $this->_options['size']); if ($id !== false) { $ret = unserialize(shmop_read($id, 0, shmop_size($id))); shmop_close($id); if ($name === false) { return $ret; } return isset($ret[$name]) ? $ret[$name] : null; } return PEAR::raiseError('Cannot open shmop.', 1); }
define('CURSOR_UP', "[%dA"); define('CURSOR_DOWN', "[%dB"); // shared memory buffer and semaphore key define('DMX_SHM_KEY', 0xff30); define('DMX_SEM_KEY', 0xff40); //Create the semaphore if (!($sem_id = sem_get(DMX_SEM_KEY, 1))) { logformat(sprintf("Could not open shared memory semaphore with key: %08X", DMX_SEM_KEY)); exit(1); } if (!($shm_id = shmop_open(DMX_SHM_KEY, 'c', 0, 512))) { logformat(sprintf("Could not open shared memory with key: %08X", DMX_SHM_KEY)); exit(1); } if ($debug) { printf("Size: %d\n", shmop_size($shm_id)); print `ipcs`; if ($s = shmop_read($shm_id, 0, 512)) { hex_print($s, 0); } } $c = 255; $nc = 512 / 4; for ($i = 0; $i < $nc; $i++) { $r2[$i] = 0; $g2[$i] = 0; $b2[$i] = 0; $r1[$i] = rand(0, 255); $g1[$i] = rand(0, 255); $b1[$i] = rand(0, 255); $s[$i * 4] = chr($c);
public function get() { $data = null; $exists = $this->exists($this->id); if ($exists) { $size = shmop_size($this->shmId); $data = unserialize(shmop_read($this->shmId, 0, $size)); } return $data; }
/** * @param $service_id * @param $component */ public function __construct($service_id, $component) { parent::__construct($service_id, $component); self::$shm_id = shmop_open(0xff3, "c", 0644, 100); self::$block_size = shmop_size(self::$shm_id); }
/** * Write data to a block of memory * * @param int $id block id to store data at * @param string $data the data to store * @return bool was the data written to memory ? */ function write_mem($id, $data) { if (shmop_size($id) < strlen($data)) { return false; } if (!shmop_write($id, $data, 0)) { //$this->log_this("Could not write to shared memory segment\n"); return false; } return true; }
public function getCapacity() { if (null === $this->m_capacity) { if (false === $this->m_segmentId) { throw new Exception_IllegalState('memory/shared/shmop', 'Can not get size of a closed shared memory segment.'); } $size = shmop_size($this->m_segmentId); if (false === $size) { return false; } $this->m_capacity = $size; } return $this->m_capacity; }