php shmop 内存读写操作
2013-02-21 17:54
176 查看
shmop php在linux上操作共享内存的函数
关于php操作内存,我选择了shmop扩展,其方法只有6个:
shmop_open 打开内存块.
shmop_write 向内存块中写入数据
shmop_size 获得内存块大小
shmop_read 读取内存块数据
shmop_delete 删除内存块数据
shmop_close 关闭内存块
第一次刷新页面,输出
input memory
第二次刷新页面,输出
get data
localhost
然后可以调用
关于php操作内存,我选择了shmop扩展,其方法只有6个:
shmop_open 打开内存块.
shmop_write 向内存块中写入数据
shmop_size 获得内存块大小
shmop_read 读取内存块数据
shmop_delete 删除内存块数据
shmop_close 关闭内存块
<?php class shared { private $shm_id; private $shm_key = 0xff3; private $shm_size = 1024; function __construct() { $this->shm_id = shmop_open($this->shm_key, "c", 0644, $this->shm_size) or die('申请失败'); } function __get($name) { $buf = shmop_read($this->shm_id, 0, $this->shm_size); $buf = unserialize(trim($buf)); if ($name == '_all') return $buf; return isset($buf[$name]) ? $buf[$name] : false; } function __set($name, $value) { $buf = shmop_read($this->shm_id, 0, $this->shm_size); $buf = unserialize(trim($buf)); $buf[$name] = $value; $buf = serialize($buf); if (strlen($buf) >= $this->shm_size) die('空间不足'); shmop_write($this->shm_id, $buf, 0) or die('写入失败'); } function del() { shmop_delete($this->shm_id); } } $shmopobj = new shared(); if (isset($shmopobj->database) || $shmopobj->database == null) { echo "input memory"; echo "</br>"; $shmopobj->database = "localhost"; } else { echo "get data"; echo "</br>"; echo $shmopobj->database; } //$shmopobj->del(); ?>
第一次刷新页面,输出
input memory
第二次刷新页面,输出
get data
localhost
然后可以调用
$shmopobj->del();删除该内存数据
相关文章推荐
- PHP文件读写操作之文件写入代码
- PHP文件读写操作相关函数总结
- [PHP学习教程 - 文件]001.高速读写大数据“二进制”文件,不必申请大内存(Byte Block)
- php读写文件操作
- php操作ACCESS(读写改)
- php入门学习知识点六 PHP文件的读写操作代码
- PHP文件系统-文件的读写操作
- php 实现Mysql读写分离操作及数据库连接类
- Python内存读写操作示例
- PHP文件读写操作相关函数总结
- PHP内存释放有关的操作
- PHP文件读写操作
- PHP中文件读写操作
- 【JavaNIO的深入研究4】内存映射文件I/O,大文件读写操作,Java nio之MappedByteBuffer,高效文件/内存映射
- PHP 大图片操作导致内存崩溃及超时的问题
- PHP中文件读写操作
- PHP读写大“二进制”文件,不必申请很大内存
- PHP使用XMLWriter读写xml文件操作详解
- php——读写文件操作
- PHP文件读写操作相关函数学习资料笔记