急!!请问php中是否可以接收来自c程序往消息队列中放的消息

dangdangstar 2005-06-02 05:29:13
我试过php往消息队列中发消息,php可以正常接收;但却接收不到c程序写的函数,往消息队列中发送的消息,还请高手指教,急!
...全文
204 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
vitalgg 2005-06-03
  • 打赏
  • 举报
回复
可以的.
检查你的 c 与 php 的操作 message queue 参数是否一致.
helloyou0 2005-06-03
  • 打赏
  • 举报
回复
应该是可以的。但是没试过

dangdangstar 2005-06-03
  • 打赏
  • 举报
回复
这是php程序,请大家帮忙看看,为何php收不到来自c发送的消息队列的消息
<?
$MSGKEY = 2345;
$msg_id = msg_get_queue($MSGKEY, 0600);
echo $msg_id;
// $MSGREV = 2346;
// $msgrev_id = msg_get_queue($MSGREV,0600);
$xml="nihao";
// if (!msg_send($msg_id,1001,$xml, true, true, $msg_err))
// echo "Msg not sent because $msg_err\n";

// echo strlen($xml);
// for($i=0;$i<100;)
//{
// echo"hello";
// $i++;
//}
$sflag=MSG_IPC_NOWAIT;

if((msg_receive ($msg_id,0,$msg_type,18566,$msg,true,$sflag,
$msg_error))==FALSE)
{
echo $msg_type;
echo "failed,$msg_error";
$errormsg= posix_strerror($msg_error);
echo $errormsg;
echo $msg;
}
else
{
echo $msg;
}

?>
dangdangstar 2005-06-03
  • 打赏
  • 举报
回复
这是c程序
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include<stdio.h>
//#include<stdlib.h>
//#include<linux/ipc.h>
//#include<linux/msg.h>
#define BUFFER 2048
struct msgtype
{
int mtype;
//char * buffer;
char buffer[BUFFER+1];
};
main()
{
int qid,sflags;
int MSGKEY = 2345;

int result,length;
struct msgtype msg;
int i = 1;

qid=msgget(MSGKEY,0600);

printf("the key of msg is %d",qid);
msg.mtype=1001;
msg.buffer[0]='a';
msgsnd(qid,&msg,sizeof(msg),sflags);
}
dangdangstar 2005-06-02
  • 打赏
  • 举报
回复
因为php支持消息队列,有往消息队列中收发消息的函数.但是我用c写的往同一个队列中放消息,为和php从消息队列中收不到呢,总说msg_receive(): message corrupted
-神仙- 2005-06-02
  • 打赏
  • 举报
回复
什么消息队列???

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧