<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.stream.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.stream-select.php',
    1 => 'stream_select',
    2 => 'Runs the equivalent of the select() system call on the given
   arrays of streams with a timeout specified by seconds and microseconds',
  ),
  'up' => 
  array (
    0 => 'ref.stream.php',
    1 => 'Stream-Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.stream-resolve-include-path.php',
    1 => 'stream_resolve_include_path',
  ),
  'next' => 
  array (
    0 => 'function.stream-set-blocking.php',
    1 => 'stream_set_blocking',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/stream/functions/stream-select.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.stream-select" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_select</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stream_select</span> &mdash; <span class="dc-title">Runs the equivalent of the select() system call on the given
   arrays of streams with a timeout specified by seconds and microseconds</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-select-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>stream_select</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter reference">&$read</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter reference">&$write</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter reference">&$except</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$seconds</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$microseconds</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span><br>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   The <span class="function"><strong>stream_select()</strong></span> function accepts arrays of streams and
   waits for them to change status. Its operation is equivalent to that of
   the <span class="function"><a href="function.socket-select.php" class="function">socket_select()</a></span> function except in that it acts on streams.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-select-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">read</code></dt>
     <dd>
      <p class="para">
       The streams listed in the <code class="parameter">read</code> array will be watched to
       see if characters become available for reading (more precisely, to see if
       a read will not block - in particular, a stream resource is also ready on
       end-of-file, in which case an <span class="function"><a href="function.fread.php" class="function">fread()</a></span> will return
       a zero length string).
      </p>
     </dd>
    
    
     <dt><code class="parameter">write</code></dt>
     <dd>
      <p class="para">
       The streams listed in the <code class="parameter">write</code> array will be
       watched to see if a write will not block.
      </p>
     </dd>
    
    
     <dt><code class="parameter">except</code></dt>
     <dd>
      <p class="para">
       The streams listed in the <code class="parameter">except</code> array will be
       watched for high priority exceptional (&quot;out-of-band&quot;) data arriving.
      </p>
      <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
       <p class="para">
        When <span class="function"><strong>stream_select()</strong></span> returns, the arrays
        <code class="parameter">read</code>, <code class="parameter">write</code> and
        <code class="parameter">except</code> are modified to indicate which stream
        resource(s) actually changed status.
        The original keys of the <a href="language.types.array.php" class="link">Array</a>s are preserved.
       </p>
      </p></blockquote>
     </dd>
    
    
     <dt><code class="parameter">seconds</code></dt>
     <dd>
      <p class="para">
       The <code class="parameter">seconds</code> and <code class="parameter">microseconds</code>
       together form the <em>timeout</em> parameter,
       <code class="parameter">seconds</code> specifies the number of seconds while
       <code class="parameter">microseconds</code> the number of microseconds.
       The <code class="parameter">timeout</code> is an upper bound on the amount of time
       that <span class="function"><strong>stream_select()</strong></span> will wait before it returns.
       If <code class="parameter">seconds</code> is set to <code class="literal">0</code> and
       <code class="parameter">microseconds</code> is <code class="literal">0</code> or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>,
       <span class="function"><strong>stream_select()</strong></span> will not wait for data - instead it will return immediately,
       indicating the current status of the streams.
      </p>
      <p class="para">
       If <code class="parameter">seconds</code> is <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> <span class="function"><strong>stream_select()</strong></span>
       can block indefinitely, returning only when an event on one of the
       watched streams occurs (or if a signal interrupts the system call).
      </p>
      <div class="warning"><strong class="warning">Warnung</strong>
       <p class="para">
        Using a timeout value of <code class="literal">0</code> allows you to
        instantaneously poll the status of the streams, however, it is NOT a
        good idea to use a <code class="literal">0</code> timeout value in a loop as it
        will cause your script to consume too much CPU time.
       </p>
       <p class="para">
        It is much better to specify a timeout value of a few seconds, although
        if you need to be checking and running other code concurrently, using a
        timeout value of at least <code class="literal">200000</code> microseconds will
        help reduce the CPU usage of your script.
       </p>
       <p class="para">
        Remember that the timeout value is the maximum time that will elapse;
        <span class="function"><strong>stream_select()</strong></span> will return as soon as the
        requested streams are ready for use.
       </p>
      </div>
     </dd>
    
    
     <dt><code class="parameter">microseconds</code></dt>
     <dd>
      <p class="para">
       See <code class="parameter">seconds</code> description.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-select-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">
   On success <span class="function"><strong>stream_select()</strong></span> returns the number of
   stream resources contained in the modified arrays, which may be zero if
   the timeout expires before anything interesting happens. On error <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>
   is returned and a warning raised (this can happen if the system call is
   interrupted by an incoming signal).
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stream-select-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Beschreibung</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.1.0</td>
      <td>
       <code class="parameter">microseconds</code> is now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-select-examples">
  <h3 class="title">Beispiele</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 <span class="function"><strong>stream_select()</strong></span> Example</strong></p>
    <div class="example-contents"><p>
     This example checks to see if data has arrived for reading on either
     <code class="parameter">$stream1</code> or <code class="parameter">$stream2</code>.
     Since the timeout value is <code class="literal">0</code> it will return
     immediately:
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/* Prepare the read array */<br /></span><span style="color: #0000BB">$read   </span><span style="color: #007700">= array(</span><span style="color: #0000BB">$stream1</span><span style="color: #007700">, </span><span style="color: #0000BB">$stream2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$write  </span><span style="color: #007700">= </span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$except </span><span style="color: #007700">= </span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br />if (</span><span style="color: #0000BB">false </span><span style="color: #007700">=== (</span><span style="color: #0000BB">$num_changed_streams </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_select</span><span style="color: #007700">(</span><span style="color: #0000BB">$read</span><span style="color: #007700">, </span><span style="color: #0000BB">$write</span><span style="color: #007700">, </span><span style="color: #0000BB">$except</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">))) {<br />    </span><span style="color: #FF8000">/* Error handling */<br /></span><span style="color: #007700">} elseif (</span><span style="color: #0000BB">$num_changed_streams </span><span style="color: #007700">&gt; </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />    </span><span style="color: #FF8000">/* At least on one of the streams something interesting happened */<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.stream-select-notes">
  <h3 class="title">Anmerkungen</h3>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Due to a limitation in the current Zend Engine it is not possible to pass a
    constant modifier like <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong> directly as a parameter to a function
    which expects this parameter to be passed by reference. Instead use a
    temporary variable or an expression with the leftmost member being a
    temporary variable:
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$e </span><span style="color: #007700">= </span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">stream_select</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">, </span><span style="color: #0000BB">$w</span><span style="color: #007700">, </span><span style="color: #0000BB">$e</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
   Be sure to use the <code class="literal">===</code> operator when checking for an
   error. Since the <span class="function"><strong>stream_select()</strong></span> may return 0 the
   comparison with <code class="literal">==</code> would evaluate to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>:
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$e </span><span style="color: #007700">= </span><span style="color: #0000BB">NULL</span><span style="color: #007700">;<br />if (</span><span style="color: #0000BB">false </span><span style="color: #007700">=== </span><span style="color: #0000BB">stream_select</span><span style="color: #007700">(</span><span style="color: #0000BB">$r</span><span style="color: #007700">, </span><span style="color: #0000BB">$w</span><span style="color: #007700">, </span><span style="color: #0000BB">$e</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">)) {<br />    echo </span><span style="color: #DD0000">"stream_select() failed\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    If you read/write to a stream returned in the arrays be aware that
    they do not necessarily read/write the full amount of data you have
    requested. Be prepared to even only be able to read/write a single
    byte.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <p class="para">
    Some streams (like <code class="literal">zlib</code>) cannot be selected by this
    function.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
   <strong>Windows compatibility</strong><br />
   <p class="para">
    Use of <span class="function"><strong>stream_select()</strong></span> on
    file descriptors returned by <span class="function"><a href="function.proc-open.php" class="function">proc_open()</a></span> will fail
    and return <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> under Windows.
   </p>
   <p class="para">
    <strong><code><a href="reserved.constants.php#constant.stdin">STDIN</a></code></strong> from a console changes status as soon as <em>any</em>
    input events are available, but reading from the stream may still block.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-select-seealso">
  <h3 class="title">Siehe auch</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.stream-set-blocking.php" class="function" rel="rdfs-seeAlso">stream_set_blocking()</a> - Set blocking/non-blocking mode on a stream</span></li>
  </ul>
 </div>

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