<?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 => 'ja',
  ),
  'this' => 
  array (
    0 => 'function.msg-receive.php',
    1 => 'msg_receive',
    2 => 'メッセージキューからメッセージを受信する',
  ),
  'up' => 
  array (
    0 => 'ref.sem.php',
    1 => 'セマフォ関数',
  ),
  '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' => 'ja',
    '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">メッセージキューからメッセージを受信する</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.msg-receive-description">
  <h3 class="title">説明</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> は、指定した <code class="parameter">queue</code>
   から指定した <code class="parameter">desired_message_type</code>
   の最初のメッセージを受信します。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.msg-receive-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt><code class="parameter">queue</code></dt>
    <dd>
     <span class="simpara">
      メッセージキュー
     </span>
    </dd>
   
   
    <dt><code class="parameter">desired_message_type</code></dt>
    <dd>
     <span class="simpara">
      <code class="parameter">desired_message_type</code> が 0 の場合、
      キューの先頭にあるメッセージが返されます。<code class="parameter">desiredmsgtype</code>
      が 0 より大きな値の場合、その型のメッセージのうち一番最初にあるものが返されます。
      <code class="parameter">desired_message_type</code> が 0 より小さな値の場合、
      <code class="parameter">desired_message_type</code>
      の絶対値と同じかそれより小さい型のメッセージのうち一番最初にあるものが返されます。
      条件を満たすメッセージがない場合は、
      条件を満たすメッセージがキューに投入されるまで待ち続けます。
      パラメータ <code class="parameter">flags</code>
      に <strong><code><a href="sem.constants.php#constant.msg-ipc-nowait">MSG_IPC_NOWAIT</a></code></strong> を指定することで、
      ブロックモードではなくすることが可能です。
     </span>
    </dd>
   
   
    <dt><code class="parameter">received_message_type</code></dt>
    <dd>
     <span class="simpara">
      受信したメッセージの型がこのパラメータに保存されます。
     </span>
    </dd>
   
   
    <dt><code class="parameter">max_message_size</code></dt>
    <dd>
     <span class="simpara">
      読み込むメッセージの最大サイズは <code class="parameter">mmax_message_size</code>
      で指定します。もしキューにあるメッセージのサイズがこれより大きい場合、
      (以下で説明する <code class="parameter">flags</code> が設定されていない限り)
      この関数は失敗します。
     </span>
    </dd>
   
   
    <dt><code class="parameter">message</code></dt>
    <dd>
     <span class="simpara">
      エラーが発生しなければ、
      受信したメッセージは <code class="parameter">message</code> に保存されます。
     </span>
    </dd>
   
   
    <dt><code class="parameter">unserialize</code></dt>
    <dd>
     <span class="simpara">
      このパラメータが <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> に設定されている場合、
      メッセージはセッションモジュールと同様の方法でシリアライズされているものとみなされます。
      メッセージは元の状態に復元されたうえでスクリプトに返されます。
      これにより、配列やオブジェクト構造体のような複雑な形式のデータを他の
      PHP スクリプトから簡単に受信することが可能となります。
      また、もし WDDX シリアライザを使用しているなら、あらゆる WDDX
      互換のソースからデータを受け取ることが可能となります。
     </span>
     <span class="simpara">
      <code class="parameter">unserialize</code> が <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> の場合、
      メッセージはバイナリセーフな文字列として返されます。
     </span>
    </dd>
   
   
    <dt><code class="parameter">flags</code></dt>
    <dd>
     <p class="para">
      オプションの <code class="parameter">flags</code> により、低レベルの
      msgrcv システムコールにフラグを渡すことが可能です。デフォルト値は 0
      ですが、以下の値のうちのいくつかを(値を足すかあるいは論理和ととることで)
      指定することが可能です。
      <table class="doctable table">
       <caption><strong>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>
           <code class="parameter">desired_message_type</code> を満たすメッセージが存在しない場合に、
           待ち続けずにすぐに結果を返します。
           関数は失敗し、<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>
           このフラグを正の <code class="parameter">desired_message_type</code>
           と組み合わせて使用すると、この関数は
           <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>
           このフラグを設定しておくと、メッセージが
           <code class="parameter">max_message_size</code> より大きい場合に
           そのメッセージを <code class="parameter">max_message_size</code> までに切り詰め、
           エラーを返しません。
          </td>
         </tr>

        </tbody>
       
      </table>

     </p>
    </dd>
   
   
    <dt><code class="parameter">error_code</code></dt>
    <dd>
     <span class="simpara">
      エラーが発生した場合は、オプションの <code class="parameter">error_code</code>
      にシステムの errno 値が設定されます。
     </span>
    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.msg-receive-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="simpara">
   成功した場合に <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を、失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
  <p class="simpara">
   処理が正常に完了すると、メッセージキューデータ構造体は以下のように更新されます。
   <code class="literal">msg_lrpid</code> には呼び出し元のプロセス ID が
   設定され、<code class="parameter">msg_qnum</code> が 1 減少し、
   <code class="literal">msg_rtime</code> が現在の時刻に設定されます。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.msg-receive-changelog">
  <h3 class="title">変更履歴</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>バージョン</th>
      <th>説明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       引数 <code class="parameter">queue</code> は、
       <span class="classname"><a href="class.sysvmessagequeue.php" class="classname">SysvMessageQueue</a></span> のインスタンスを期待するようになりました。
       これより前のバージョンでは、リソースが期待されていました。
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 seealso" id="refsect1-function.msg-receive-seealso">
  <h3 class="title">参考</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.msg-remove-queue.php" class="function" rel="rdfs-seeAlso">msg_remove_queue()</a> - メッセージキューを破棄する</span></li>
   <li><span class="function"><a href="function.msg-send.php" class="function" rel="rdfs-seeAlso">msg_send()</a> - メッセージキューにメッセージを送信する</span></li>
   <li><span class="function"><a href="function.msg-stat-queue.php" class="function" rel="rdfs-seeAlso">msg_stat_queue()</a> - メッセージキューデータ構造体の情報を返す</span></li>
   <li><span class="function"><a href="function.msg-set-queue.php" class="function" rel="rdfs-seeAlso">msg_set_queue()</a> - メッセージキューデータ構造体の情報を設定する</span></li>
  </ul>
 </div>


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