Commit 36989c5
committed
Update TTY checks
The function `stream_isatty()` ([PHP manual](https://www.php.net/manual/en/function.stream-isatty.php)) is available since PHP 7.2.0/8.0.
> Determines if stream stream refers to a valid terminal type device. This is a more portable version of posix_isatty(), since it works on Windows systems too.
This update also enables the use of an Output stream as an argument without triggering a warning, as in the folowing code.
```
define( 'STDOUT', fopen( 'php://output', 'w' ) );
var_dump(posix_isatty(STDOUT));
var_dump(stream_isatty(STDOUT));
=>
<b>Warning</b>: posix_isatty(): could not use stream of type 'Output' in <b>/usr/local/var/www/wp-cli/php/boot-fpm.php</b> on line <b>22</b><br />
bool(false)
bool(false)
```
It is necessary to define `STDOUT` in this way while using the `fpm-fcgi` SAPI. This is useful when running lots of WP-CLI commands in a high-volume task scheduler where up to 95% of CPU time is wasted on the redundant work of loading PHP code. We found that php-fpm's opcode caching reduces resource usage significantly, idling hundreds of CPUs that are otherwise occupied loading the same code over and over again.
The `fpm-fcgi` SAPI runs WP CLI through a modified boot script. A command line program passes commands via an FCGI client and returns results on standard streams. This work will also be contributed to the `wp-cli` project.1 parent e472e08 commit 36989c5
2 files changed
+10
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
95 | 99 | | |
96 | 100 | | |
97 | 101 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
0 commit comments