<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
  <refentry id="function.msg-receive">
   <refnamediv>
    <refname>msg_receive</refname>
    <refpurpose>
     Receive a message from a message queue
    </refpurpose>
   </refnamediv>
   <refsect1>
    <title>Description</title>
    <methodsynopsis>
     <type>bool</type><methodname>msg_receive</methodname>
     <methodparam><type>resource</type><parameter>queue</parameter></methodparam>
     <methodparam><type>int</type><parameter>desiredmsgtype</parameter></methodparam>
     <methodparam><type>int</type><parameter role="reference">msgtype</parameter></methodparam>
     <methodparam><type>int</type><parameter>maxsize</parameter></methodparam>
     <methodparam><type>mixed</type><parameter role="reference">message</parameter></methodparam>
     <methodparam choice="opt"><type>bool</type><parameter>unserialize</parameter></methodparam>
     <methodparam choice="opt"><type>int</type><parameter>flags</parameter></methodparam>
     <methodparam choice="opt"><type>int</type><parameter role="reference">errorcode</parameter></methodparam>
    </methodsynopsis>
    <para>
     <function>msg_receive</function> will receive the first message from the
     specified <parameter>queue</parameter> of the type specified by
     <parameter>desiredmsgtype</parameter>.
     The type of the message that was received will be stored in
     <parameter>msgtype</parameter>.
     The maximum size of message to be accepted is specified by the
     <parameter>maxsize</parameter>; if the message in the queue is larger
     than this size the function will fail (unless you set
     <parameter>flags</parameter> as described below).
     The received message will be stored in <parameter>message</parameter>,
     unless there were errors receiving the message, in which case the
     optional <parameter>errorcode</parameter> will be set to the value of the
     system errno variable to help you identify the cause.
    </para>
    <para>
     If <parameter>desiredmsgtype</parameter> is 0, the message from the front
     of the queue is returned. If <parameter>desiredmsgtype</parameter> is
     greater than 0, then the first message of that type is returned.
     If <parameter>desiredmsgtype</parameter> is less than 0, the first
     message on the queue with the lowest type less than or equal to the
     absolute value of <parameter>desiredmsgtype</parameter> 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 <constant>MSG_IPC_NOWAIT</constant> in the 
     <parameter>flags</parameter> parameter.
    </para>
    <para>
     <parameter>unserialize</parameter> defaults to &true;; if it is set to
     &true;, 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 <parameter>unserialize</parameter> is &false;, the message will be
     returned as a binary-safe string.
    </para>
    <para>
     The optional <parameter>flags</parameter> 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).
     <table>
      <title>Flag values for msg_receive</title>
      <tgroup cols="2">
       <tbody>
        <row>
         <entry><constant>MSG_IPC_NOWAIT</constant></entry> 
         <entry>If there are no messages of the
          <parameter>desiredmsgtype</parameter>, return immediately and do not
          wait.  The function will fail and return an integer value
          corresponding to ENOMSG.
         </entry>
        </row>
        <row>
         <entry><constant>MSG_EXCEPT</constant></entry>
         <entry>Using this flag in combination with a
          <parameter>desiredmsgtype</parameter> greater than 0 will cause the
          function to receive the first message that is not equal to
          <parameter>desiredmsgtype</parameter>.</entry>
        </row>
        <row>
         <entry><constant>MSG_NOERROR</constant></entry> 
         <entry>
          If the message is longer than <parameter>maxsize</parameter>,
          setting this flag will truncate the message to
          <parameter>maxsize</parameter> and will not signal an error.
         </entry>
        </row>
       </tbody>
      </tgroup>
     </table>
    </para>
    <para>
     Upon successful completion the message queue data structure is updated as
     follows: <literal>msg_lrpid</literal> is set to the process-ID of the
     calling process, <literal>msg_qnum</literal> is decremented by 1 and
     <literal>msg_rtime</literal> is set to the current time.
    </para>
    <para>
     <function>msg_receive</function> returns &true; on success or &false; on
     failure.  If the function fails, the optional
     <parameter>errorcode</parameter> will be set to the value of the system
     errno variable.
    </para>
    <para>
     See also <function>msg_remove_queue</function>,
     <function>msg_send</function>,
     <function>msg_stat_queue</function> and
     <function>msg_set_queue</function>.
    </para>
   </refsect1>
  </refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->