php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39982 when used inside a function, proc_open generated pipes are closed upon return
Submitted: 2006-12-29 01:13 UTC Modified: 2006-12-29 10:54 UTC
From: federico at galassi dot net Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 5.2.0 OS: gentoo linux
Private report: No CVE-ID: None
 [2006-12-29 01:13 UTC] federico at galassi dot net
Description:
------------
When calling proc_open inside the body
of a function, pipes generated don't survive
function's lifespan. resource is still there
but stream is closed.

Reproduce code:
---------------
function foobar() {
    $proc = proc_open(
        "/usr/bin/php",
        array(
            0 => array('pipe', 'r'),
            1 => array('pipe', 'w'),
            2 => array('pipe', 'w')
        ),
        $pipes
    );
    var_dump($pipes);
    return $pipes;
}
$should_be_pipes = foobar();
var_dump($should_be_pipes);

Expected result:
----------------
array(3) {
  [0]=>
  resource(6) of type (stream)
  [1]=>
  resource(7) of type (stream)
  [2]=>
  resource(8) of type (stream)
}
array(3) {
  [0]=>
  resource(6) of type (stream)
  [1]=>
  resource(7) of type (stream)
  [2]=>
  resource(8) of type (stream)
}

Actual result:
--------------
array(3) {
  [0]=>
  resource(6) of type (stream)
  [1]=>
  resource(7) of type (stream)
  [2]=>
  resource(8) of type (stream)
}
array(3) {
  [0]=>
  resource(6) of type (Unknown)
  [1]=>
  resource(7) of type (Unknown)
  [2]=>
  resource(8) of type (Unknown)
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-29 10:54 UTC] tony2001@php.net
The $pipes are dependant resources of the $proc, so if $proc dies, they are closed too.
Return both $proc and $pipes and everything will be ok.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 21:01:29 2024 UTC