您的位置:首页 > 编程语言 > PHP开发

PHP IPC函数介绍---共享内存

2012-11-23 09:31 225 查看
以下是php的共享内存常用函数,用于进程间的通信

shm_attach — Creates or open a shared memory segment
shm_detach — Disconnects from shared memory segment
shm_get_var — Returns a variable from shared memory
shm_has_var — Check whether a specific entry exists
shm_put_var — Inserts or updates a variable in shared memory
shm_remove_var — Removes a variable from shared memory
shm_remove — Removes shared memory from Unix systems

$msg_key=1;
$ipc_key=ftok(__FILE__,'t');
$seg=shm_attach($ipc_key,1024,0600); //创建或打开一个共享内存段
if(!$seg){
die('create or open shared memory segment failed!');
}
shm_put_var($seg,$msg_key,'hello world');
if(shm_has_var($seg,$msg_key)){
$content=shm_get_var($seg,$msg_key);
echo $content;
}
shm_remove_var($seg,$msg_key);
shm_remove($seg);


输出:hello world
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: