因为php支持消息队列,有往消息队列中收发消息的函数.但是我用c写的往同一个队列中放消息,为和php从消息队列中收不到呢,总说msg_receive(): message corrupted

解决方案 »

  1.   

    可以的.
    检查你的 c 与 php 的操作 message queue 参数是否一致.
      

  2.   

    这是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);
    }
      

  3.   

    这是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;
     }?>