<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >msg_receive</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="Semaphore, Shared Memory and IPC Functions" HREF="ref.sem.html"><LINK REL="PREVIOUS" TITLE="msg_get_queue" HREF="function.msg-get-queue.html"><LINK REL="NEXT" TITLE="msg_remove_queue" HREF="function.msg-remove-queue.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.msg-get-queue.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.msg-remove-queue.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.msg-receive" ></A >msg_receive</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN205521" ></A ><P > (PHP 4 >= 4.3.0, PHP 5)</P >msg_receive -- Receive a message from a message queue </DIV ><DIV CLASS="refsect1" ><A NAME="AEN205524" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >msg_receive</B > ( resource queue, int desiredmsgtype, int &msgtype, int maxsize, mixed &message [, bool unserialize [, int flags [, int &errorcode]]] )<BR ></BR ><P > <B CLASS="function" >msg_receive()</B > will receive the first message from the specified <CODE CLASS="parameter" >queue</CODE > of the type specified by <CODE CLASS="parameter" >desiredmsgtype</CODE >. The type of the message that was received will be stored in <CODE CLASS="parameter" >msgtype</CODE >. The maximum size of message to be accepted is specified by the <CODE CLASS="parameter" >maxsize</CODE >; if the message in the queue is larger than this size the function will fail (unless you set <CODE CLASS="parameter" >flags</CODE > as described below). The received message will be stored in <CODE CLASS="parameter" >message</CODE >, unless there were errors receiving the message, in which case the optional <CODE CLASS="parameter" >errorcode</CODE > will be set to the value of the system errno variable to help you identify the cause. </P ><P > If <CODE CLASS="parameter" >desiredmsgtype</CODE > is 0, the message from the front of the queue is returned. If <CODE CLASS="parameter" >desiredmsgtype</CODE > is greater than 0, then the first message of that type is returned. If <CODE CLASS="parameter" >desiredmsgtype</CODE > is less than 0, the first message on the queue with the lowest type less than or equal to the absolute value of <CODE CLASS="parameter" >desiredmsgtype</CODE > will be read. If no messages match the criteria, your script will wait until a suitable message arrives on the queue. You can prevent the script from blocking by specifying <TT CLASS="constant" ><B >MSG_IPC_NOWAIT</B ></TT > in the <CODE CLASS="parameter" >flags</CODE > parameter. </P ><P > <CODE CLASS="parameter" >unserialize</CODE > defaults to <TT CLASS="constant" ><B >TRUE</B ></TT >; if it is set to <TT CLASS="constant" ><B >TRUE</B ></TT >, the message is treated as though it was serialized using the same mechanism as the session module. The message will be unserialized and then returned to your script. This allows you to easily receive arrays or complex object structures from other PHP scripts, or if you are using the WDDX serializer, from any WDDX compatible source. If <CODE CLASS="parameter" >unserialize</CODE > is <TT CLASS="constant" ><B >FALSE</B ></TT >, the message will be returned as a binary-safe string. </P ><P > The optional <CODE CLASS="parameter" >flags</CODE > allows you to pass flags to the low-level msgrcv system call. It defaults to 0, but you may specify one or more of the following values (by adding or ORing them together). <DIV CLASS="table" ><A NAME="AEN205577" ></A ><P ><B >表 1. Flag values for msg_receive</B ></P ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><TBODY ><TR ><TD ><TT CLASS="constant" ><B >MSG_IPC_NOWAIT</B ></TT ></TD ><TD >If there are no messages of the <CODE CLASS="parameter" >desiredmsgtype</CODE >, return immediately and do not wait. The function will fail and return an integer value corresponding to <TT CLASS="constant" ><B >MSG_ENOMSG</B ></TT >. </TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >MSG_EXCEPT</B ></TT ></TD ><TD >Using this flag in combination with a <CODE CLASS="parameter" >desiredmsgtype</CODE > greater than 0 will cause the function to receive the first message that is not equal to <CODE CLASS="parameter" >desiredmsgtype</CODE >.</TD ></TR ><TR ><TD ><TT CLASS="constant" ><B >MSG_NOERROR</B ></TT ></TD ><TD > If the message is longer than <CODE CLASS="parameter" >maxsize</CODE >, setting this flag will truncate the message to <CODE CLASS="parameter" >maxsize</CODE > and will not signal an error. </TD ></TR ></TBODY ></TABLE ></DIV > </P ><P > Upon successful completion the message queue data structure is updated as follows: <TT CLASS="literal" >msg_lrpid</TT > is set to the process-ID of the calling process, <TT CLASS="literal" >msg_qnum</TT > is decremented by 1 and <TT CLASS="literal" >msg_rtime</TT > is set to the current time. </P ><P > <B CLASS="function" >msg_receive()</B > returns <TT CLASS="constant" ><B >TRUE</B ></TT > on success or <TT CLASS="constant" ><B >FALSE</B ></TT > on failure. If the function fails, the optional <CODE CLASS="parameter" >errorcode</CODE > will be set to the value of the system errno variable. </P ><P > See also <A HREF="function.msg-remove-queue.html" ><B CLASS="function" >msg_remove_queue()</B ></A >, <A HREF="function.msg-send.html" ><B CLASS="function" >msg_send()</B ></A >, <A HREF="function.msg-stat-queue.html" ><B CLASS="function" >msg_stat_queue()</B ></A > and <A HREF="function.msg-set-queue.html" ><B CLASS="function" >msg_set_queue()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.msg-get-queue.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.msg-remove-queue.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >msg_get_queue</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.sem.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >msg_remove_queue</TD ></TR ></TABLE ></DIV ></BODY ></HTML >