#44217 [Fbk]: Output after stdout/stderr closed cause immediate exit
| From: | jani@php.net | Date: | Sun, 24 Feb 2008 00:40:01 +0000 |
| Subject: | #44217 [Fbk]: Output after stdout/stderr closed cause immediate exit | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-122623@lists.php.net to get a copy of this message | ||
ID: 44217
Updated by: jani@php.net
Reported By: exe at travian dot org
Status: Feedback
Bug Type: Filesystem function related
Operating System: GNU/Linux Kernel 2.6.18
PHP Version: 5.2.5
New Comment:
Another bug #44218 describes some more expected behaviour caused by
closing the input/output streams.
NOTE: Correct manual page:
http://www.php.net/manual/en/wrappers.php.php
Previous Comments:
------------------------------------------------------------------------
[2008-02-24 00:34:08] jani@php.net
That's quite expected since you're still trying to output to STDOUT.
Why do you want to close STDOUT anyway?
See also: http://www.php.net/wrappers.php
------------------------------------------------------------------------
[2008-02-22 17:32:15] exe at travian dot org
Description:
------------
If STDOUT and/or STDERR are closed, output by the php script cause the
interpreter to exit immediately.
According to strace output, php tries to write to the closed STDOUT
file handle, causing a "Bad file descriptor" error and exit of the
interpreter:
[...]
close(1) = 0
[...]
write(1, "foo", 3) = -1 EBADF (Bad file
descriptor)
close(0) = 0
close(2) = 0
[...]
exit_group(0) = ?
Process 19177 detached
Reproduce code:
---------------
<?php
fclose(STDOUT);
print "foo";
sleep(10);
?>
Expected result:
----------------
No output, php sleeping for 10 seconds.
Actual result:
--------------
php exits immediately, strace shows an "Bad file descriptor" on the
write() try to STDOUT:
[...]
read(3, "<?php\nfclose(STDOUT);\n\nprint \"fo"..., 8192) = 51
read(3, "", 4096) = 0
read(3, "", 8192) = 0
close(3) = 0
munmap(0x2b1dce200000, 4096) = 0
close(1) = 0
munmap(0x2b1dce202000, 4096) = 0
write(1, "foo", 3) = -1 EBADF (Bad file
descriptor)
close(2) = 0
close(0) = 0
munmap(0x2b1dce201000, 4096) = 0
munmap(0x2b1dce1bf000, 266240) = 0
mmap(NULL, 266240, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x2b1dce1bf000
setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) =
0
munmap(0x2b1dce1bf000, 266240) = 0
brk(0xd36000) = 0xd36000
exit_group(0) = ?
Process 19196 detached
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44217&edit=1