• 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

  • 相关阅读:
    前端-JavaScript
    前端-HTML
    Python源程序(.py)转换为可执行文件(.exe)
    进程
    算法之动态规划问题
    算法之斐波那契数列
    贪心算法找零问题
    算法之迷宫问题
    数据结构相关知识
    常用排序算法
  • 原文地址:https://www.cnblogs.com/xiazh/p/2783040.html
Copyright © 2020-2023  润新知