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

以下是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

posted @ 2012-11-23 09:31  涛光  阅读(1217)  评论(0编辑  收藏  举报