php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49015 PHP doesn't close STDIN,STDOUT,STDERR correct.
Submitted: 2009-07-22 13:43 UTC Modified: 2009-07-23 08:39 UTC
From: tsc at netuse dot de Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 5.3.0 OS: SUSE LINUX 10.0
Private report: No CVE-ID: None
 [2009-07-22 13:43 UTC] tsc at netuse dot de
Description:
------------
Description:
------------
This is the same bug as reported and fixed for PHP5
http://bugs.php.net/bug.php?id=27865 and 32107 , but is still present in 5.3.0.

PHP doesn't close STDIN,STDOUT,STDERR correct.

I have the same Issues on Ubuntu 6 LTS.

Reproduce code:
---------------
<?php

$stdout = fopen("php://stdout",w);

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,32107 (PHP5, fixed)
 */

?>


Expected result:
----------------
X-Powered-By: PHP/5.3.0
Content-type: text/html

<br />
<b>Warning</b>:  fwrite(): 3 is not a valid stream resource in <b>/srv/www/wwwenv3.0/sbin/test_fork.php</b> on line <b>8</b><br />
Stdout still open



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-22 20:10 UTC] jani@php.net
You're not closing stdout there. You're closing stream opened to 
php://stdout which is different to what PHP itself uses, a.k.a. STDOUT. 
See also bug #44217
 [2009-07-23 08:39 UTC] tsc at netuse dot de
Ok, but i have the problem, that STDOUT isn't defined when i call php from cli.

My main problem is, that i want to damonize my php script and STDOUT,STDIN,STDERR wouldn't closed correctly.

Here is my test Script:

<?php

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

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

?>

Here the Output:

./php -n test.php      
X-Powered-By: PHP/5.3.0
Content-type: text/html

<br />
<b>Warning</b>:  fwrite() expects parameter 1 to be resource, string given in <b>/srv/www/wwwenv3.0/sbin/test.php</b> on line <b>5</b><br />
<br />
<b>Warning</b>:  fclose() expects parameter 1 to be resource, string given in <b>/srv/www/wwwenv3.0/sbin/test.php</b> on line <b>6</b><br />
Stdout still open)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC