Как установить связь между php и библиотекой Boost IPC?

У меня есть клиент и сервер в php, которые обмениваются данными через общую память. Теперь я хотел бы получить доступ к этому объекту памяти с помощью Boost.Interprocess, как я могу получить к нему доступ? server.php:

  function create_image($str){
  // Create a blank image and add some text
  $im = imagecreatetruecolor(300, 20);
  $text_color = imagecolorallocate($im, 233, 14, 91);
  $stringBanner=exec("date").$str;
  imagestring($im, 1, 5, 5,  $stringBanner , $text_color);

  ob_start();
   imagejpeg($im);
  $i = ob_get_contents();
  ob_get_clean(); 
  imagedestroy($im);
   return $i; 
  }  
  echo "\n".__FILE__."\n";
  $shm_key = ftok(__FILE__, 't');
  echo $shm_key."\n";


  $shm_id = shmop_open($shm_key, "a", 0, 0); 
 if ($shm_id) {
  //it is already created
  shmop_delete($shm_id);
  shmop_close($shm_id); 
 } 
 //you need to create it with shmop_open using "c" only
 echo "try to create\n";
 if(!$shm_id = shmop_open($shm_key, "c", 0777, 1024*4))exit(-1);


 echo "ID ".$shm_id."\n";
 $i=0;
 for(;;){
 sleep(1);
 $s="i=".$i++;
 $str=$i;
 $im=serialize(create_image($str));

 $data=serialize(strlen($im));
 $shm_bytes_written = shmop_write($shm_id, $data, 0);
 $shm_bytes_written = shmop_write($shm_id, $im, 32);
 echo $shm_bytes_written." bytes  is written: ".$s." ID = $shm_id\n";
}

client.php

Какой ключ я должен предоставить Boost, чтобы получить эту область памяти?

boost_client.cpp

#include  
#include  
#include "sys/msg.h"

int main() 
{ 
    int msqid;
    key_t key;
    char f[]="??????";
    int mid;

    //key = ftok(, 't');
    //msqid = msgget(key, 0666 | IPC_CREAT);

    std::cout<

РЕДАКТИРОВАТЬ:

Я нашел решение в документации библиотеки Boost IPC:

Пример на основе XSI_KEY из документации boost

13
задан Micha 21 June 2013 в 05:06
поделиться