Source of: /manual/en/function.msg-receive.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sem.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.msg-receive.php',
1 => 'msg_receive',
),
'up' =>
array (
0 => 'ref.sem.php',
1 => 'Semaphore Functions',
),
'prev' =>
array (
0 => 'function.msg-queue-exists.php',
1 => 'msg_queue_exists',
),
'next' =>
array (
0 => 'function.msg-remove-queue.php',
1 => 'msg_remove_queue',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.msg-receive" class="refentry">
<div class="refnamediv">
<h1 class="refname">msg_receive</h1>
<p class="verinfo">(PHP 4 >= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">msg_receive</span> — <span class="dc-title">Receive a message from a message queue</span></p>
</div>
<a name="function.msg-receive.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">bool</span> <span class="methodname"><b>msg_receive</b></span>
( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$queue</tt></span>
, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$desiredmsgtype</tt></span>
, <span class="methodparam"><span class="type">int</span> <tt class="parameter reference">&$msgtype</tt></span>
, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$maxsize</tt></span>
, <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter reference">&$message</tt></span>
[, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$unserialize</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$flags</tt></span>
[, <span class="methodparam"><span class="type">int</span> <tt class="parameter reference">&$errorcode</tt></span>
]]] )</div>
<p class="para rdfs-comment">
<b>msg_receive()</b> will receive the first message from the
specified <i><tt class="parameter">queue</tt></i>
of the type specified by
<i><tt class="parameter">desiredmsgtype</tt></i>
.
</p>
</div>
<a name="function.msg-receive.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">queue</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">desiredmsgtype</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
If <i><tt class="parameter">desiredmsgtype</tt></i>
is 0, the message from the front
of the queue is returned. If <i><tt class="parameter">desiredmsgtype</tt></i>
is
greater than 0, then the first message of that type is returned.
If <i><tt class="parameter">desiredmsgtype</tt></i>
is less than 0, the first
message on the queue with the lowest type less than or equal to the
absolute value of <i><tt class="parameter">desiredmsgtype</tt></i>
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 <b><tt class="constant">MSG_IPC_NOWAIT</tt></b> in the
<i><tt class="parameter">flags</tt></i>
parameter.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">msgtype</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The type of the message that was received will be stored in this
parameter.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">maxsize</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The maximum size of message to be accepted is specified by the
<i><tt class="parameter">maxsize</tt></i>
; if the message in the queue is larger
than this size the function will fail (unless you set
<i><tt class="parameter">flags</tt></i>
as described below).
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">message</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The received message will be stored in <i><tt class="parameter">message</tt></i>
,
unless there were errors receiving the message.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">unserialize</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
<i><tt class="parameter">unserialize</tt></i>
defaults to <b><tt class="constant">TRUE</tt></b>; if it is set to
<b><tt class="constant">TRUE</tt></b>, 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.
</p>
<p class="para">
If <i><tt class="parameter">unserialize</tt></i>
is <b><tt class="constant">FALSE</tt></b>, the message will be
returned as a binary-safe string.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">flags</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The optional <i><tt class="parameter">flags</tt></i>
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).
</p><table class="doctable table">
<caption><b>Flag values for msg_receive</b></caption>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left"><b><tt class="constant">MSG_IPC_NOWAIT</tt></b></td>
<td align="left">If there are no messages of the
<i><tt class="parameter">desiredmsgtype</tt></i>
, return immediately and do not
wait. The function will fail and return an integer value
corresponding to <b><tt class="constant">MSG_ENOMSG</tt></b>.
</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">MSG_EXCEPT</tt></b></td>
<td align="left">Using this flag in combination with a
<i><tt class="parameter">desiredmsgtype</tt></i>
greater than 0 will cause the
function to receive the first message that is not equal to
<i><tt class="parameter">desiredmsgtype</tt></i>
.</td>
</tr>
<tr valign="middle">
<td align="left"><b><tt class="constant">MSG_NOERROR</tt></b></td>
<td align="left">
If the message is longer than <i><tt class="parameter">maxsize</tt></i>
,
setting this flag will truncate the message to
<i><tt class="parameter">maxsize</tt></i>
and will not signal an error.
</td>
</tr>
</tbody>
</table>
<p>
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">errorcode</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
If the function fails, the optional <i><tt class="parameter">errorcode</tt></i>
will be set to the value of the system errno variable.
</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.msg-receive.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns <b><tt class="constant">TRUE</tt></b> on success or <b><tt class="constant">FALSE</tt></b> on failure.
</p>
<p class="para">
Upon successful completion the message queue data structure is updated as
follows: <i>msg_lrpid</i> is set to the process-ID of the
calling process, <i>msg_qnum</i> is decremented by 1 and
<i>msg_rtime</i> is set to the current time.
</p>
</div>
<a name="function.msg-receive.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.msg-remove-queue.php" class="function" rel="rdfs-seeAlso">msg_remove_queue()</a> - Destroy a message queue</li>
<li class="member"><a href="function.msg-send.php" class="function" rel="rdfs-seeAlso">msg_send()</a> - Send a message to a message queue</li>
<li class="member"><a href="function.msg-stat-queue.php" class="function" rel="rdfs-seeAlso">msg_stat_queue()</a> - Returns information from the message queue data structure</li>
<li class="member"><a href="function.msg-set-queue.php" class="function" rel="rdfs-seeAlso">msg_set_queue()</a> - Set information in the message queue data structure</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>