stream_isatty.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. 'Not a stream' => 'foo',
  15. 'Invalid stream (php://temp)' => fopen('php://temp', 'wb'),
  16. 'Invalid stream (php://input)' => fopen('php://input', 'wb'),
  17. 'Invalid stream (php://memory)' => fopen('php://memory', 'wb'),
  18. 'File stream' => $closeMe = fopen(__FILE__, 'rb'),
  19. );
  20. foreach ($sampleStreams as $name => $stream) {
  21. echo "$name: "; var_dump(stream_isatty($stream));
  22. }
  23. fclose($closeMe);
  24. }
  25. function testToStdErr()
  26. {
  27. ob_start();
  28. testToStdOut();
  29. $result = ob_get_contents();
  30. ob_end_clean();
  31. fwrite(STDERR, $result);
  32. }