What potential pitfalls should be considered when using stream_select in PHP for console output handling?

When using stream_select in PHP for console output handling, it is important to consider potential pitfalls such as blocking behavior if the streams are not set to non-blocking mode, as well as the need to handle errors and timeouts properly. To avoid these issues, make sure to set the streams to non-blocking mode and handle any errors or timeouts that may occur during the stream selection process.

$read = array(STDIN);
$write = null;
$except = null;

if (stream_select($read, $write, $except, 0) === false) {
    // Handle error
} elseif (stream_select($read, $write, $except, 0) > 0) {
    $input = fgets(STDIN);
    // Handle input
}