getKey(), $memsize, $perm))) { throw new \RuntimeException("Unable to attach shm resource {$key}"); } $this->resource = $shm_resource; } /** * Destructor */ public function __destruct() { if (!$this->resource) { return; } shmop_close($this->resource); } /** * Destroy the memory block * * @return void */ public function destroy() { shmop_delete($this->resource); shmop_close($this->resource); $this->resource = null; } /** * Read bytes from the shared block * * @param integer $length * @param integer $offset * @return mixed */ public function read($length=0, $offset=0) { if ($length == 0) { $length = shmop_size($this->resource) - $offset; } return shmop_read($this->resource, $offset, $length); } /** * Write bytes to the shared block * * @param mixed $data * @param integer $offset * @return integer */ public function write($data, $offset=0):int { return shmop_write($this->resource, $data, $offset); } /** * Get the size of the memory block * * @return integer */ public function getSize():int { return shmop_size($this->resource); } }