4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 define('ERR_SELECT_FAILED', 1);
13 define('ERR_TIMEOUT', 2);
14 define('ERR_READ_FAILED', 3);
15 define('ERR_WRITE_FAILED', 4);
18 $write = array(STDOUT, STDERR);
20 stream_set_blocking(STDIN, 0);
21 stream_set_blocking(STDOUT, 0);
22 stream_set_blocking(STDERR, 0);
25 while ($read || $write) {
29 $n = stream_select($r, $w, $e, 5);
32 die(ERR_SELECT_FAILED);
37 if (in_array(STDOUT, $w) && strlen($out) > 0) {
38 $written = fwrite(STDOUT, (binary) $out, 32768);
39 if (false === $written) {
40 die(ERR_WRITE_FAILED);
42 $out = (binary) substr($out, $written);
44 if (null === $read && '' === $out) {
45 $write = array_diff($write, array(STDOUT));
48 if (in_array(STDERR, $w) && strlen($err) > 0) {
49 $written = fwrite(STDERR, (binary) $err, 32768);
50 if (false === $written) {
51 die(ERR_WRITE_FAILED);
53 $err = (binary) substr($err, $written);
55 if (null === $read && '' === $err) {
56 $write = array_diff($write, array(STDERR));
60 $str = fread(STDIN, 32768);
65 if (false === $str || feof(STDIN)) {