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