php-doc-en/reference/sem/functions/msg-receive.xml

203 lines
7.1 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.msg-receive">
<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>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><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">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>.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>queue</parameter></term>
<listitem>
<para>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>desiredmsgtype</parameter></term>
<listitem>
<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>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>msgtype</parameter></term>
<listitem>
<para>
The type of the message that was received will be stored in this
parameter.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>maxsize</parameter></term>
<listitem>
<para>
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).
</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>desiredmsgtype</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>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>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>errorcode</parameter></term>
<listitem>
<para>
If the function fails, the optional <parameter>errorcode</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="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
-->