Skip to content

Instantly share code, notes, and snippets.

@jubianchi
Created October 24, 2012 13:11
Show Gist options
  • Save jubianchi/3945969 to your computer and use it in GitHub Desktop.
Save jubianchi/3945969 to your computer and use it in GitHub Desktop.
PHP & STDOUT
#!/usr/bin/env php
<?php
var_dump(defined('STDOUT'));
var_dump(@fopen('php://stdout', 'w'));
## PHP 5.3.15
$ php ./stdout.php
# bool(true)
# resource(5) of type (stream)
$ curl -s file://`pwd`/stdout.php | php
# bool(false)
# resource(2) of type (stream)
## PHP 5.4.5
$ php ./stdout.php
# bool(true)
# resource(5) of type (stream)
$ curl -s file://`pwd`/stdout.php | php
# bool(false)
# resource(2) of type (stream)
$ echo '<?php var_dump(defined("STDOUT"));' | php
# bool(false)
@chx
Copy link

chx commented Oct 24, 2012

I do not get your problem. http://php.net/manual/en/features.commandline.io-streams.php clearly says These constants are not available if reading the PHP script from stdin.

@chx
Copy link

chx commented Oct 24, 2012

Note: that page is the second result for https://www.google.com/search?complete=0&q=php+stdout

@jubianchi
Copy link
Author

I read these pages but I was asking what is the point of this behavior ?
Piping to PHP means that it does not have an actual STDOUT ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment