e22redir.php PHP redir stdout, achtung läuft nur in CLI!!!
e22redir.php
e22redir.php
echo 1 begin sapi=cgi-fcgi, defined(STDOUT) = false, at 2025-05-21T18:56:12+02:00
catch exception = Error: Undefined constant "STDOUT" in /home/ch45859/web/wlkl.ch/public_html/inf/php/e22redir.php:9
Stack trace:
#0 {main}
End e22redir.php
args
e22redir.php
/home/ch45859/web/wlkl.ch/public_html/inf/php/e22redir.php
*** code does not have a span berfore first <br>***<html>
<h2><?php echo basename(__file__); ?> PHP redir stdout, achtung läuft nur in CLI!!!</h3>
<?php
require_once('env.php');
outBegin();
try {
echo '<br>echo 1 begin sapi=' . php_sapi_name() . ', defined(STDOUT) = ' . (defined('STDOUT') ? 'true' : 'false') . ', at ' . date('c') ."\n";
$old = posix_ttyname(STDOUT);
echo '<br> 2>old tty=' . $old . "\n";
fclose(STDOUT);
$STDOUT = fopen('e22redir.out', 'w');
echo '<br>echo 3 after redir ' . date('c');
fclose($STDOUT);
$STDOUT = fopen($old, 'w');
echo "<br>echo 4 after redir back\n";
echo "<br>contents of e22redir.out ==> " . file_get_contents('e22redir.out') . "\n";
} catch (Throwable $e) {
echo "<br> catch exception = " . $e;
}
outEnd(__file__);
?>