gh8827-003.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. std handles can be deliberately closed 003
  3. --SKIPIF--
  4. <?php
  5. if (php_sapi_name() != "cli") {
  6. die("skip CLI only");
  7. }
  8. if (PHP_OS_FAMILY == 'Windows') {
  9. die("skip not for Windows");
  10. }
  11. if (PHP_DEBUG) {
  12. die("skip std streams are not closeable in debug builds");
  13. }
  14. if (getenv('SKIP_REPEAT')) {
  15. die("skip cannot be repeated");
  16. }
  17. ?>
  18. --FILE--
  19. <?php
  20. $stdoutStream = fopen('php://stdout', 'r');
  21. $stdoutFile = tempnam(sys_get_temp_dir(), 'gh8827');
  22. $stderrFile = tempnam(sys_get_temp_dir(), 'gh8827');
  23. register_shutdown_function(function () use ($stdoutFile, $stderrFile) {
  24. unlink($stdoutFile);
  25. unlink($stderrFile);
  26. });
  27. fclose(STDOUT);
  28. fclose(STDERR);
  29. $stdoutFileStream = fopen($stdoutFile, 'a');
  30. $stderrFileStream = fopen($stderrFile, 'a');
  31. print "Goes to stdoutFile\n";
  32. file_put_contents('php://fd/1', "Also goes to stdoutFile\n");
  33. file_put_contents('php://fd/2', "Goes to stderrFile\n");
  34. ob_start(function ($buffer) use ($stdoutStream) {
  35. fwrite($stdoutStream, $buffer);
  36. }, 1);
  37. print "stdoutFile:\n";
  38. readfile($stdoutFile);
  39. print "stderrFile:\n";
  40. readfile($stderrFile);
  41. ?>
  42. --EXPECT--
  43. stdoutFile:
  44. Goes to stdoutFile
  45. Also goes to stdoutFile
  46. stderrFile:
  47. Goes to stderrFile