Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP stdout on Apache

Tags:

php

apache

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

Where does stdout go in the above configuration?

Tested with following code:

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

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

This only displays output in the browser. What happens to stdout?

like image 907
tkocjan Avatar asked Jul 03 '12 20:07

tkocjan


1 Answers

As the manual shows on the php:// wrappers manual page:

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

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

On the other hand, php://stdout

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

In the case of Apache, this output is Apache's stdout handle which is generally never seen anywhere because this is console output for Apache and it is usually run in the background. If you were to run Apache in the foreground on your console, anything you write to php://stdout would be visible on the console. Since Apache is run in the background, no stdout data is captured or written anywhere normally.

To test this, follow these steps:

  • Run Apache in the foreground (e.g. /usr/local/apache2/bin/httpd -D FOREGROUND -k start)
  • Leave the console window open
  • Run your script from the browser
  • Look for your stdout output on the console.
like image 112
drew010 Avatar answered Oct 05 '22 19:10

drew010