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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: federico at galassi dot net
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 19:01:31 2025 UTC