You can write directly to the tty (screen) even when the shell has redirected output, with:
<?php
$h = fopen(posix_ctermid(), "rb+");
fwrite($h, "Testing direct output\n");
fclose($h);
?>
PHP - Manual: posix_ctermid
2024-12-22
(PHP 4, PHP 5, PHP 7, PHP 8)
posix_ctermid — Get path name of controlling terminal
Generates a string which is the pathname for the current controlling terminal for the process. On error this will set errno, which can be checked using posix_get_last_error()
此函数没有参数。
Upon successful completion, returns string of the pathname to
the current controlling terminal. Otherwise false
is returned and errno
is set, which can be checked with posix_get_last_error().
示例 #1 posix_ctermid() example
This example will display the path to the current TTY.
<?php
echo "I am running from ".posix_ctermid();
?>
You can write directly to the tty (screen) even when the shell has redirected output, with:
<?php
$h = fopen(posix_ctermid(), "rb+");
fwrite($h, "Testing direct output\n");
fclose($h);
?>
官方地址:https://www.php.net/manual/en/function.posix-ctermid.php