大佬教程收集整理的这篇文章主要介绍了如何在php和boost库之间进行通信?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
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,$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); 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
<?PHP $shm_key =1946222626;// ftok(__FILE__,'t'); $shm_id = shmop_open( $shm_key,0644,1024*4 ); $s=shmop_size($shm_id); $data = unserialize( shmop_read( $shm_id,31) ); $im = unserialize( shmop_read( $shm_id,32,$data) ); // Set the content type header - in this case image/jpeg header('Content-Type: image/jpeg'); // Output the image echo $im;
我应该提供什么样的关键技术来提升这个记忆区域?
boost_client.cpp
#include <boost/interprocess/shared_memory_object.hpp> #include <iostream> #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<<msqid<<std::endl; boost::interprocess::shared_memory_object shdmem(boost::interprocess::open_or_create,f,//"shmem_server",boost::interprocess::read_writE); shdmem.truncate(1024); std::cout << shdmem.get_name() << std::endl; boost::interprocess::offset_t size; if (shdmem.get_size(sizE)) std::cout << size << std::endl; }
编辑:
那么我在Boost IPC库中找到了解决方案文档:
以上是大佬教程为你收集整理的如何在php和boost库之间进行通信?全部内容,希望文章能够帮你解决如何在php和boost库之间进行通信?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。