Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a34ed6838d4b29d38abd504392a4a797 > files > 2530

php-manual-es-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>stream_select</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual de PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Stream functions"
HREF="ref.stream.html"><LINK
REL="PREVIOUS"
TITLE="stream_register_wrapper"
HREF="function.stream-register-wrapper.html"><LINK
REL="NEXT"
TITLE="stream_set_blocking"
HREF="function.stream-set-blocking.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual de PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.stream-register-wrapper.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.stream-set-blocking.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.stream-select"
></A
>stream_select</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN73968"
></A
><P
>    (PHP 4 &#62;= 4.3.0)</P
>stream_select&nbsp;--&nbsp;Runs the equivalent of the select() system call on the given 
     arrays of streams with a timeout specified by tv_sec and tv_usec </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN73971"
></A
><H2
>Description</H2
>int <B
CLASS="methodname"
>stream_select</B
> ( resource &#38;read, resource &#38;write, resource &#38;except, int tv_sec [, int tv_usec])<BR
></BR
><P
>&#13;     The <B
CLASS="function"
>stream_select()</B
> function accepts arrays of streams and
     waits for them to change status. Its opperation is equivalent to that of
     the <A
HREF="function.socket-select.html"
><B
CLASS="function"
>socket_select()</B
></A
> function except in that it acts on streams.
    </P
><P
>&#13;     The streams listed in the <TT
CLASS="parameter"
><I
>read</I
></TT
> 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 <A
HREF="function.fread.html"
><B
CLASS="function"
>fread()</B
></A
> will return
     a zero length string).
    </P
><P
>&#13;     The streams listed in the <TT
CLASS="parameter"
><I
>write</I
></TT
> array will be
     watched to see if a write will not block.
    </P
><P
>&#13;     The streams listed in the <TT
CLASS="parameter"
><I
>except</I
></TT
> array will be
     watched for exceptions.
    </P
><DIV
CLASS="warning"
><P
></P
><TABLE
CLASS="warning"
BORDER="1"
WIDTH="100%"
><TR
><TD
ALIGN="CENTER"
><B
>Aviso</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
><P
>&#13;      On exit, the arrays are modified to indicate which stream resource
      actually changed status.
     </P
></TD
></TR
></TABLE
></DIV
><P
>&#13;     You do not need to pass every array to
     <B
CLASS="function"
>stream_select()</B
>. You can leave it out and use an
     empty array or <TT
CLASS="constant"
><B
>NULL</B
></TT
> instead. Also do not forget that those arrays are
     passed <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>by reference</I
></SPAN
> and will be modified after
     <B
CLASS="function"
>stream_select()</B
> returns.
    </P
><P
>&#13;     Example:
     <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>/* Prepare the read array */
$read = array($stream1, $stream2);

if (false === ($num_changed_streams = stream_select($read, $write = NULL, $except = NULL, 0))) {
    /* Error handling */
else if ($num_changed_streams &#62; 0) {
    /* At least on one of the streams something interesting happened */
}</PRE
></TD
></TR
></TABLE
>
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      Due a limitation in the current Zend Engine it is not possible to pass a
      constant modifier like <TT
CLASS="constant"
><B
>NULL</B
></TT
> 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:
      <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>stream_select($r, $w, $e = NULL, 0);</PRE
></TD
></TR
></TABLE
>
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     The <TT
CLASS="parameter"
><I
>tv_sec</I
></TT
> and <TT
CLASS="parameter"
><I
>tv_usec</I
></TT
>
     together form the <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>timeout</I
></SPAN
> parameter. The
     <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>timeout</I
></SPAN
> is an upper bound on the amount of time
     elapsed before <B
CLASS="function"
>stream_select()</B
> returns.
     <TT
CLASS="parameter"
><I
>tv_sec</I
></TT
> may be zero , causing
     <B
CLASS="function"
>stream_select()</B
> to return immediately. This is useful
     for polling. If <TT
CLASS="parameter"
><I
>tv_sec</I
></TT
> is <TT
CLASS="constant"
><B
>NULL</B
></TT
> (no timeout),
     <B
CLASS="function"
>stream_select()</B
> can block indefinitely.
    </P
><P
>&#13;     On success <B
CLASS="function"
>stream_select()</B
> returns the number of
     stream resorces contained in the modified arrays, which may be zero if
     the timeout expires before anything interesting happens. On error <TT
CLASS="constant"
><B
>FALSE</B
></TT
>
     is returned.
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
     Be sure to use the <TT
CLASS="literal"
>===</TT
> operator when checking for an
     error. Since the <B
CLASS="function"
>stream_select()</B
> may return 0 the
     comparison with <TT
CLASS="literal"
>==</TT
> would evaluate to <TT
CLASS="constant"
><B
>TRUE</B
></TT
>:
     <TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>if (false === stream_select($r, $w, $e = NULL, 0)) {
    echo "stream_select() failed\n";
}</PRE
></TD
></TR
></TABLE
>
     </P
></BLOCKQUOTE
></DIV
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      Be aware that some stream implementations need to be handled very
      carefully. A few basic rules:
      <P
></P
><UL
><LI
><P
>&#13;         You should always try to use <B
CLASS="function"
>stream_select()</B
>
         without timeout. Your program should have nothing to do if there is
         no data available. Code that depends on timeouts is not usually
         portable and difficult to debug.
        </P
></LI
><LI
><P
>&#13;         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
></LI
></UL
>
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     See also
     <A
HREF="function.stream-set-blocking.html"
><B
CLASS="function"
>stream_set_blocking()</B
></A
>
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.stream-register-wrapper.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Inicio</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.stream-set-blocking.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>stream_register_wrapper</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.stream.html"
ACCESSKEY="U"
>Subir</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>stream_set_blocking</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>