<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.msg-receive" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>msg_receive</refname>
  <refpurpose>Receive a message from a message queue</refpurpose>
 </refnamediv>
 
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>bool</type><methodname>msg_receive</methodname>
   <methodparam><type>SysvMessageQueue</type><parameter>queue</parameter></methodparam>
   <methodparam><type>int</type><parameter>desired_message_type</parameter></methodparam>
   <methodparam><type>int</type><parameter role="reference">received_message_type</parameter></methodparam>
   <methodparam><type>int</type><parameter>max_message_size</parameter></methodparam>
   <methodparam><type>mixed</type><parameter role="reference">message</parameter></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>unserialize</parameter><initializer>&true;</initializer></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer>0</initializer></methodparam>
   <methodparam choice="opt"><type>int</type><parameter role="reference">error_code</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>
   <function>msg_receive</function> will receive the first message from the
   specified <parameter>queue</parameter> of the type specified by
   <parameter>desired_message_type</parameter>.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>queue</parameter></term>
     <listitem>
      <para>
       The message queue.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>desired_message_type</parameter></term>
     <listitem>
      <para>
       If <parameter>desired_message_type</parameter> is 0, the message from the front
       of the queue is returned. If <parameter>desired_message_type</parameter> is
       greater than 0, then the first message of that type is returned.
       If <parameter>desired_message_type</parameter> is less than 0, the first
       message on the queue with a type less than or equal to the
       absolute value of <parameter>desired_message_type</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>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>received_message_type</parameter></term>
     <listitem>
      <para>
       The type of the message that was received will be stored in this
       parameter.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>max_message_size</parameter></term>
     <listitem>
      <para>
       The maximum size of message to be accepted is specified by the
       <parameter>max_message_size</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).
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>message</parameter></term>
     <listitem>
      <para>
       The received message will be stored in <parameter>message</parameter>,
       unless there were errors receiving the message.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>unserialize</parameter></term>
     <listitem>
      <para>
       If 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.
      </para>
      <para>
       If <parameter>unserialize</parameter> is &false;, the message will be
       returned as a binary-safe string.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>flags</parameter></term>
     <listitem>
      <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>desired_message_type</parameter>, return immediately and do not
            wait.  The function will fail and return an integer value
            corresponding to <constant>MSG_ENOMSG</constant>.
           </entry>
          </row>
          <row>
           <entry><constant>MSG_EXCEPT</constant></entry>
           <entry>Using this flag in combination with a
            <parameter>desired_message_type</parameter> greater than 0 will cause the
            function to receive the first message that is not equal to
            <parameter>desired_message_type</parameter>.</entry>
          </row>
          <row>
           <entry><constant>MSG_NOERROR</constant></entry>
           <entry>
            If the message is longer than <parameter>max_message_size</parameter>,
            setting this flag will truncate the message to
            <parameter>max_message_size</parameter> and will not signal an error.
           </entry>
          </row>
         </tbody>
        </tgroup>
       </table>
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>error_code</parameter></term>
     <listitem>
      <para>
       If the function fails, the optional <parameter>error_code</parameter>
       will be set to the value of the system errno variable.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </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>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>8.0.0</entry>
       <entry>
        <parameter>queue</parameter> expects a <classname>SysvMessageQueue</classname>
        instance now; previously, a <type>resource</type> was expected.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>
 
 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>msg_remove_queue</function></member>
    <member><function>msg_send</function></member>
    <member><function>msg_stat_queue</function></member>
    <member><function>msg_set_queue</function></member>
   </simplelist>
  </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:"~/.phpdoc/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
-->
