PHP.nl

stream_select

stream_select

Runs the equivalent of the select() system call on the given arrays of streams with a timeout specified by seconds and microseconds

 **stream_select**  $read  $write  $except  $seconds  $microseconds

The function accepts arrays of streams and waits for them to change status. Its operation is equivalent to that of the function except in that it acts on streams. stream_select``socket_select

read The streams listed in the 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 will return a zero length string). read``fread

write The streams listed in the array will be watched to see if a write will not block. write

except The streams listed in the array will be watched for high priority exceptional ("out-of-band") data arriving. except

Opmerking: > When returns, the arrays , and are modified to indicate which stream resource(s) actually changed status. The original keys of the arrays are preserved. stream_select``read``write``except

seconds The and together form the parameter, specifies the number of seconds while the number of microseconds. The is an upper bound on the amount of time that will wait before it returns. If and are both set to , will not wait for data - instead it will return immediately, indicating the current status of the streams. seconds``microsecondstimeoutseconds``microseconds``timeout``stream_select``seconds``microseconds``0``stream_select

   If  is null 
   can block indefinitely, returning only when an event on one of the
   watched streams occurs (or if a signal interrupts the system call).
  `seconds``stream_select`

Waarschuwing: > Using a timeout value of allows you to instantaneously poll the status of the streams, however, it is NOT a good idea to use a timeout value in a loop as it will cause your script to consume too much CPU time. 0``0

    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  microseconds will
    help reduce the CPU usage of your script.
   `200000`


    Remember that the timeout value is the maximum time that will elapse;
     will return as soon as the
    requested streams are ready for use.
   `stream_select`

microseconds See description. seconds

On success 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 false is returned and a warning raised (this can happen if the system call is interrupted by an incoming signal). stream_select

Voorbeeld: Example

 This example checks to see if data has arrived for reading on either
  or .
 Since the timeout value is  it will return
 immediately:
`$stream1``$stream2``0`
<?php
/* Prepare the read array */
$read   = array($stream1, $stream2);
$write  = NULL;
$except = NULL;
if (false === ($num_changed_streams = stream_select($read, $write, $except, 0))) {
    /* Error handling */
} elseif ($num_changed_streams > 0) {
    /* At least on one of the streams something interesting happened */
}
?>

Opmerking: > Due to a limitation in the current Zend Engine it is not possible to pass a constant modifier like null 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:

<?php
$e = NULL;
stream_select($r, $w, $e, 0);
?>

Opmerking: > Be sure to use the operator when checking for an error. Since the may return 0 the comparison with would evaluate to true:

`===stream_select==````php

Opmerking: > 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.

Opmerking: > Some streams (like ) cannot be selected by this function. zlib

Opmerking: > ### Windows compatibility

Use of  on
file descriptors returned by  will fail
and return false under Windows.

stream_select``proc_open

 from a console changes status as soon as 
input events are available, but reading from the stream may still block.

STDINany

stream_set_blocking