<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Receive a message from a message queue</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.msg-queue-exists.html">msg_queue_exists</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.msg-remove-queue.html">msg_remove_queue</a></div> <div class="up"><a href="ref.sem.html">Semaphore Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><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> <div class="refsect1 description" id="refsect1-function.msg-receive-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>msg_receive</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$queue</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$desiredmsgtype</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$msgtype</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$maxsize</code></span> , <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter reference">&$message</code></span> [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$unserialize</code><span class="initializer"> = true</span></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$errorcode</code></span> ]]] )</div> <p class="para rdfs-comment"> <span class="function"><strong>msg_receive()</strong></span> will receive the first message from the specified <em><code class="parameter">queue</code></em> of the type specified by <em><code class="parameter">desiredmsgtype</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.msg-receive-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">queue</code></em></span> <dd> <p class="para"> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">desiredmsgtype</code></em></span> <dd> <p class="para"> If <em><code class="parameter">desiredmsgtype</code></em> is 0, the message from the front of the queue is returned. If <em><code class="parameter">desiredmsgtype</code></em> is greater than 0, then the first message of that type is returned. If <em><code class="parameter">desiredmsgtype</code></em> is less than 0, the first message on the queue with the lowest type less than or equal to the absolute value of <em><code class="parameter">desiredmsgtype</code></em> 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 <strong><code>MSG_IPC_NOWAIT</code></strong> in the <em><code class="parameter">flags</code></em> parameter. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">msgtype</code></em></span> <dd> <p class="para"> The type of the message that was received will be stored in this parameter. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">maxsize</code></em></span> <dd> <p class="para"> The maximum size of message to be accepted is specified by the <em><code class="parameter">maxsize</code></em>; if the message in the queue is larger than this size the function will fail (unless you set <em><code class="parameter">flags</code></em> as described below). </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">message</code></em></span> <dd> <p class="para"> The received message will be stored in <em><code class="parameter">message</code></em>, unless there were errors receiving the message. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">unserialize</code></em></span> <dd> <p class="para"> If set to <strong><code>TRUE</code></strong>, 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 <em><code class="parameter">unserialize</code></em> is <strong><code>FALSE</code></strong>, the message will be returned as a binary-safe string. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">flags</code></em></span> <dd> <p class="para"> The optional <em><code class="parameter">flags</code></em> 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 class="doctable table"> <caption><strong>Flag values for msg_receive</strong></caption> <tbody class="tbody"> <tr> <td><strong><code>MSG_IPC_NOWAIT</code></strong></td> <td>If there are no messages of the <em><code class="parameter">desiredmsgtype</code></em>, return immediately and do not wait. The function will fail and return an integer value corresponding to <strong><code>MSG_ENOMSG</code></strong>. </td> </tr> <tr> <td><strong><code>MSG_EXCEPT</code></strong></td> <td>Using this flag in combination with a <em><code class="parameter">desiredmsgtype</code></em> greater than 0 will cause the function to receive the first message that is not equal to <em><code class="parameter">desiredmsgtype</code></em>.</td> </tr> <tr> <td><strong><code>MSG_NOERROR</code></strong></td> <td> If the message is longer than <em><code class="parameter">maxsize</code></em>, setting this flag will truncate the message to <em><code class="parameter">maxsize</code></em> and will not signal an error. </td> </tr> </tbody> </table> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">errorcode</code></em></span> <dd> <p class="para"> If the function fails, the optional <em><code class="parameter">errorcode</code></em> will be set to the value of the system errno variable. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.msg-receive-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> <p class="para"> Upon successful completion the message queue data structure is updated as follows: <em>msg_lrpid</em> is set to the process-ID of the calling process, <em>msg_qnum</em> is decremented by 1 and <em>msg_rtime</em> is set to the current time. </p> </div> <div class="refsect1 seealso" id="refsect1-function.msg-receive-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.msg-remove-queue.html" class="function" rel="rdfs-seeAlso">msg_remove_queue()</a> - Destroy a message queue</span></li> <li class="member"> <span class="function"><a href="function.msg-send.html" class="function" rel="rdfs-seeAlso">msg_send()</a> - Send a message to a message queue</span></li> <li class="member"> <span class="function"><a href="function.msg-stat-queue.html" class="function" rel="rdfs-seeAlso">msg_stat_queue()</a> - Returns information from the message queue data structure</span></li> <li class="member"> <span class="function"><a href="function.msg-set-queue.html" class="function" rel="rdfs-seeAlso">msg_set_queue()</a> - Set information in the message queue data structure</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.msg-queue-exists.html">msg_queue_exists</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.msg-remove-queue.html">msg_remove_queue</a></div> <div class="up"><a href="ref.sem.html">Semaphore Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>