<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = 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 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.msg-receive.php',
    1 => 'msg_receive',
    2 => 'Receive a message from a message queue',
  ),
  'up' => 
  array (
    0 => 'ref.sem.php',
    1 => 'Semaphore Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.msg-queue-exists.php',
    1 => 'msg_queue_exists',
  ),
  'next' => 
  array (
    0 => 'function.msg-remove-queue.php',
    1 => 'msg_remove_queue',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/sem/functions/msg-receive.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.msg-receive" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">msg_receive</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">msg_receive</span> &mdash; <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">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>msg_receive</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.sysvmessagequeue.php" class="type SysvMessageQueue">SysvMessageQueue</a></span> <code class="parameter">$queue</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$desired_message_type</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter reference">&$received_message_type</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$max_message_size</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter reference">&$message</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$unserialize</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$flags</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter reference">&$error_code</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="simpara">
   <span class="function"><strong>msg_receive()</strong></span> will receive the first message from the
   specified <code class="parameter">queue</code> of the type specified by
   <code class="parameter">desired_message_type</code>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.msg-receive-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">queue</code></dt>
    <dd>
     <span class="simpara">
      The message queue.
     </span>
    </dd>
   
   
    <dt><code class="parameter">desired_message_type</code></dt>
    <dd>
     <span class="simpara">
      If <code class="parameter">desired_message_type</code> is 0, the message from the front
      of the queue is returned. If <code class="parameter">desired_message_type</code> is
      greater than 0, then the first message of that type is returned.
      If <code class="parameter">desired_message_type</code> is less than 0, the first
      message on the queue with a type less than or equal to the
      absolute value of <code class="parameter">desired_message_type</code> 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><a href="sem.constants.php#constant.msg-ipc-nowait">MSG_IPC_NOWAIT</a></code></strong> in the
      <code class="parameter">flags</code> parameter.
     </span>
    </dd>
   
   
    <dt><code class="parameter">received_message_type</code></dt>
    <dd>
     <span class="simpara">
      The type of the message that was received will be stored in this
      parameter.
     </span>
    </dd>
   
   
    <dt><code class="parameter">max_message_size</code></dt>
    <dd>
     <span class="simpara">
      The maximum size of message to be accepted is specified by the
      <code class="parameter">max_message_size</code>; if the message in the queue is larger
      than this size the function will fail (unless you set
      <code class="parameter">flags</code> as described below).
     </span>
    </dd>
   
   
    <dt><code class="parameter">message</code></dt>
    <dd>
     <span class="simpara">
      The received message will be stored in <code class="parameter">message</code>,
      unless there were errors receiving the message.
     </span>
    </dd>
   
   
    <dt><code class="parameter">unserialize</code></dt>
    <dd>
     <span class="simpara">
      If set to
      <strong><code><a href="reserved.constants.php#constant.true">true</a></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.
     </span>
     <span class="simpara">
      If <code class="parameter">unserialize</code> is <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, the message will be
      returned as a binary-safe string.
     </span>
    </dd>
   
   
    <dt><code class="parameter">flags</code></dt>
    <dd>
     <p class="para">
      The optional <code class="parameter">flags</code> 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><a href="sem.constants.php#constant.msg-ipc-nowait">MSG_IPC_NOWAIT</a></code></strong></td>
          <td>If there are no messages of the
           <code class="parameter">desired_message_type</code>, return immediately and do not
           wait.  The function will fail and return an integer value
           corresponding to <strong><code><a href="sem.constants.php#constant.msg-enomsg">MSG_ENOMSG</a></code></strong>.
          </td>
         </tr>

         <tr>
          <td><strong><code><a href="sem.constants.php#constant.msg-except">MSG_EXCEPT</a></code></strong></td>
          <td>Using this flag in combination with a
           <code class="parameter">desired_message_type</code> greater than 0 will cause the
           function to receive the first message that is not equal to
           <code class="parameter">desired_message_type</code>.</td>
         </tr>

         <tr>
          <td><strong><code><a href="sem.constants.php#constant.msg-noerror">MSG_NOERROR</a></code></strong></td>
          <td>
           If the message is longer than <code class="parameter">max_message_size</code>,
           setting this flag will truncate the message to
           <code class="parameter">max_message_size</code> and will not signal an error.
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
   
    <dt><code class="parameter">error_code</code></dt>
    <dd>
     <span class="simpara">
      If the function fails, the optional <code class="parameter">error_code</code>
      will be set to the value of the system errno variable.
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.msg-receive-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="simpara">
   Restituisce <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> in caso di successo, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
  <p class="simpara">
   Upon successful completion the message queue data structure is updated as
   follows: <code class="literal">msg_lrpid</code> is set to the process-ID of the
   calling process, <code class="literal">msg_qnum</code> is decremented by 1 and
   <code class="literal">msg_rtime</code> is set to the current time.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.msg-receive-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versione</th>
      <th>Descrizione</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">queue</code> expects a <span class="classname"><a href="class.sysvmessagequeue.php" class="classname">SysvMessageQueue</a></span>
       instance now; previously, a <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was expected.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.msg-receive-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.msg-remove-queue.php" class="function" rel="rdfs-seeAlso">msg_remove_queue()</a> - Destroy a message queue</span></li>
   <li><span class="function"><a href="function.msg-send.php" class="function" rel="rdfs-seeAlso">msg_send()</a> - Send a message to a message queue</span></li>
   <li><span class="function"><a href="function.msg-stat-queue.php" class="function" rel="rdfs-seeAlso">msg_stat_queue()</a> - Returns information from the message queue data structure</span></li>
   <li><span class="function"><a href="function.msg-set-queue.php" class="function" rel="rdfs-seeAlso">msg_set_queue()</a> - Set information in the message queue data structure</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>