stream_isatty.inc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. function testToStdOut()
  3. {
  4. $sampleStreams = array(
  5. 'STDIN (constant)' => STDIN,
  6. 'STDIN (fopen)' => fopen('php://stdin', 'rb'),
  7. 'STDIN (php://fd/0)' => fopen('php://fd/0', 'rb'),
  8. 'STDOUT (constant)' => STDOUT,
  9. 'STDOUT (fopen)' => fopen('php://stdout', 'wb'),
  10. 'STDOUT (php://fd/1)' => fopen('php://fd/1', 'wb'),
  11. 'STDERR (constant)' => STDERR,
  12. 'STDERR (fopen)' => fopen('php://stderr', 'wb'),
  13. 'STDERR (php://fd/2)' => fopen('php://fd/2', 'wb'),
  14. 'Invalid stream (php://temp)' => fopen('php://temp', 'wb'),
  15. 'Invalid stream (php://input)' => fopen('php://input', 'wb'),
  16. 'Invalid stream (php://memory)' => fopen('php://memory', 'wb'),
  17. 'File stream' => $closeMe = fopen(__FILE__, 'rb'),
  18. );
  19. foreach ($sampleStreams as $name => $stream) {
  20. echo "$name: "; var_dump(stream_isatty($stream));
  21. }
  22. fclose($closeMe);
  23. }
  24. function testToStdErr()
  25. {
  26. ob_start();
  27. testToStdOut();
  28. $result = ob_get_contents();
  29. ob_end_clean();
  30. fwrite(STDERR, $result);
  31. }