Input/output streams
The CLI SAPI defines a few constants for I/O streams to make programming for the command line a bit easier.
| Constant | Description |
|---|---|
STDIN | An already opened stream to <?phpstdin, you can use<?php |
STDOUTAn already opened stream to stdout. This saves opening it with
<?php
$stdout = fopen('php://stdout', 'w');
?>STDERRAn already opened stream to stderr. This saves opening it with
<?php
$stderr = fopen('php://stderr', 'w');
?>Given the above, you don't need to open e.g. a stream for stderr yourself but simply use the constant instead of the stream resource:
php -r 'fwrite(STDERR, "stderr\n");'
Note:
These constants are not available if reading the PHP script from
stdin.
↑ and ↓ to navigate • Enter to select • Esc to close • / to open