xref: /php-src/sapi/cli/tests/gh8827-003.phpt (revision 0a4a55fd)
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}
11?>
12--FILE--
13<?php
14
15$stdoutStream = fopen('php://stdout', 'r');
16
17$stdoutFile = tempnam(sys_get_temp_dir(), 'gh8827');
18$stderrFile = tempnam(sys_get_temp_dir(), 'gh8827');
19register_shutdown_function(function () use ($stdoutFile, $stderrFile) {
20    unlink($stdoutFile);
21    unlink($stderrFile);
22});
23
24fclose(STDOUT);
25fclose(STDERR);
26
27$stdoutFileStream = fopen($stdoutFile, 'a');
28$stderrFileStream = fopen($stderrFile, 'a');
29
30print "Goes to stdoutFile\n";
31file_put_contents('php://fd/1', "Also goes to stdoutFile\n");
32
33file_put_contents('php://fd/2', "Goes to stderrFile\n");
34
35ob_start(function ($buffer) use ($stdoutStream) {
36    fwrite($stdoutStream, $buffer);
37}, 1);
38
39print "stdoutFile:\n";
40readfile($stdoutFile);
41
42print "stderrFile:\n";
43readfile($stderrFile);
44
45?>
46--EXPECT--
47stdoutFile:
48Goes to stdoutFile
49Also goes to stdoutFile
50stderrFile:
51Goes to stderrFile
52