php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32107 fclose (STDIN|STDOUT|STDERR) not working
Submitted: 2005-02-25 12:54 UTC Modified: 2005-08-06 01:00 UTC
Votes:12
Avg. Score:4.2 ± 0.9
Reproduced:11 of 11 (100.0%)
Same Version:3 (27.3%)
Same OS:2 (18.2%)
From: php at the-eend dot org Assigned:
Status: No Feedback Package: CGI/CLI related
PHP Version: 4.3.10 OS: Redhat ES3
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-02-25 12:54 UTC] php at the-eend dot org
Description:
------------
This is the same bug as reported and fixed for PHP5 last year: http://bugs.php.net/bug.php?id=27865 , but is still present in 4.3.10.
Upgrading to PHP 5 is not an option at this point. Any chance this can be back-ported?


With CLI scripts, fclosing STDIN, STDOUT and STDERR have no effect, leaving the sockets open, and the terminal which ran the script hanging.

Reproduce code:
---------------
echo STDIN . '|' . STDOUT . '|' . STDERR . "\n";
fclose (STDIN);
fclose (STDOUT);
fclose (STDERR);
echo STDIN . '|' . STDOUT . '|' . STDERR . "\n";


Expected result:
----------------
The STDIN, STDOUT and STDERR streams should be closed:

Resource id #1|Resource id #2|Resource id #3
||

(perhaps, though this would mean the value of a 'constant' was being changed...)

Actual result:
--------------
The streams are not closed, and remain pointing to the same resources:

Resource id #1|Resource id #2|Resource id #3
Resource id #1|Resource id #2|Resource id #3

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-25 13:03 UTC] tony2001@php.net
Why do you think they are not closed?
<?php
var_dump(STDIN);
fclose (STDIN);
var_dump(fread(STDIN, 10));
?>
Or use var_dump() in your example:
<?php
var_dump(STDIN);
fclose (STDIN);
var_dump(STDIN);
?>
 [2005-02-25 13:33 UTC] php at the-eend dot org
True enough, the resource goes from being a stream to an "Unknown".
Unfortunately, my terminal still hangs until the script is complete when I try to log out of the server. If the stream is truly closed (not saying I don't believe you ;)), I guess it must be something else. :(

I sense an incoming "bogus"... ;)
 [2005-02-25 14:09 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-03-20 18:01 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 [2005-07-29 13:01 UTC] Andreas dot Oesterhelt at InTradeSys dot com
Here's the test case requested by tony2001@php.net:

<?php

fclose(STDOUT);

/* This now fails..*/
fwrite (STDOUT, "Test");

/* but this still works: */
echo "Stdout still open\n";

/*
 * Standard output is still open.
 * The process is therefore unable to detach from its terminal.
 * See PHP Bug #27865 (PHP5, fixed)
 */

?>

Tested in PHP 4.3.10 (cli)
 [2005-07-29 15:35 UTC] wez@php.net
Please try it with PHP 5
 [2005-08-06 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2005-10-10 23:30 UTC] valerio at wnet dot it
This bug is still present in php 4.3.10.

Any chance to have it fixed in the 4.3 tree?
 [2006-04-27 18:52 UTC] matxgx at hotmail dot com
I actually am experiencing the same issue, as witnessed below using PHP 5.1.2

gillespiem@localhost ~/src/php $ php -v
PHP 5.1.2-gentoo (cli) (built: Apr 27 2006 10:49:04)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
gillespiem@localhost ~/src/php $ php std3.php 

Warning: fwrite(): 2 is not a valid stream resource in /home/gillespiem/src/php/std3.php on line 6
Stdout still open


Any advice would be greatly appreciated.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Feb 20 00:01:25 2019 UTC