我们知道php中可以用shm_open来打开一段共享内存,用shmp_write来向共享内存中写内容,但shmp_write只支持字符串形式,我们能否创建一种机制能够共享一个对象呢?希望高手们发表高见
有谁知道对象的内存结构,就是对象在内存中怎样存贮的
<?php
//定义类
class test
{
var $num = '';
function show()
{
echo $this->num;
}
}
//申请共享内存空间
$shm_id = shmop_open(0xff3, "c", 0644, 100);
//实例化test对象
$exam = new test();
$exam->num = 'ok';
//序列化test对象
$value = serialize($exam);
//写入共享内存空间
shmop_write($shm_id, $value, 0);
//获取共享内存空间中的内容
$my_string = shmop_read($shm_id, 0, strlen($value));
//反序列化
$haha = unserialize($my_string);
//输出test对象的num成员值
echo $haha->num;
//释放共享内存空间
shmop_delete($shm_id);
shmop_close($shm_id);
?>
更详细描述请参考php manual
http://expert.csdn.net/Expert/topic/2995/2995563.xml?temp=.1943018
<<上一页




