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

相关文章:

  • 2021-07-11
  • 2021-08-14
  • 2021-07-03
  • 2022-12-23
  • 2022-03-05
  • 2021-07-17
  • 2021-11-25
  • 2021-04-21
猜你喜欢
  • 2021-10-29
  • 2021-07-25
  • 2022-12-23
  • 2021-07-10
  • 2021-04-11
  • 2021-10-03
相关资源
相似解决方案