PHP stdout on Apache

Using PHP 5.3 as php5_module in Apache 2.2 on Windows 7.

Where is stdout located in the above configuration?

Tested with the following code:

<?php $stdout = fopen('php://stdout', 'w'); fwrite($stdout, "stdout<br />\n"); $output = fopen('php://output', 'w'); fwrite($output, "output<br />\n"); ?> 

Only output displayed in the browser. What happens to stdout?

+7
source share
1 answer

As shown in the manual on the php: // wrappers page:

php: // output is a write-only stream that allows you to write to the output buffer mechanism in the same way as printing and echoing .

So, if you want to write the output to the browser, use php://output

php://stdout , on the other hand

allow direct access to the corresponding input or output stream of the PHP process.

In the case of Apache, this output is an Apache descriptor descriptor that usually never occurs because it is console output for Apache and it usually runs in the background. If you want to run Apache in the foreground on the console, everything you write in php://stdout will be visible on the console. Because Apache runs in the background, stdout data is not written or written anywhere.

To verify this, follow these steps:

  • Launch Apache in the foreground (e.g. /usr/local/apache2/bin/httpd -D FOREGROUND -k start )
  • Leave the console window open.
  • Run the script from the browser
  • Look at your stdout output on the console.
+18
source

All Articles