php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33828 processes opened with proc_open may freeze on fatal error
Submitted: 2005-07-22 20:33 UTC Modified: 2005-07-23 15:24 UTC
From: vesely at tana dot it Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: 4.4.0 OS: Unix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
21 - 6 = ?
Subscribe to this entry?

 
 [2005-07-22 20:33 UTC] vesely at tana dot it
Description:
------------
If the proc_open was inside a class object,
then on a fatal error the child process
is not killed. (Both CLI and Apache.)

That behaviour makes it difficult to develop
scripts based on classes using proc_open.

If the $proc is not inside a class object,
I obtained a similar freezing doing $proc = 0
before the fatal error.


Reproduce code:
---------------
<?php
class my_class
{
   var $proc, $pipes;	
   function my_class() {
      $this->proc = proc_open("cat -",
         array(
            0 => array("pipe", "r"),
            1 => array("file", "/dev/null", "w"),
            2 => array("file", "/dev/null", "w")),
         $this->pipes);	
   }
}

$p = new my_class();
printf("%s proc hangs on fatal PHP error?\n",
   is_resource($p->proc) ? "Open" : "Not open");
non_existing_function("hangs if open");
// not reached...
?>



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-22 23:15 UTC] tony2001@php.net
It's fixed in 5.x, but I don't think that the fix will get into 4.4.0 ever, as it was just a small part of exec()/proc_open() overall rewrite.
So I'd say you have to live with that (or use 5.x instead, this is a perfect reason to start using it).

 [2005-07-23 15:24 UTC] vesely at tana dot it
Perhaps you may check the following code, please?

When migrating to 5.x we will have to review c'tors
anyway, so it seems fine to me. Strange as it looks,
I wouldn't bet about unwanted side effects. If you
feel like recommending it, I'll post a pointer to this
bug in the relevant manual page.

Workaround code:
----------------
<?php
class my_class
{
   var $proc, $pipes;
   function my_class() {
      // open in c'tor hangs on fatal error
      // $this->open();
   }

   function open() {
      $this->proc = proc_open("cat -",
         array(
            0 => array("pipe", "r"),
            1 => array("file", "/dev/null", "w"),
            2 => array("file", "/dev/null", "w")),
         $this->pipes);
      $GLOBALS[uniqid("my_class_proc_open_")] = $this->proc;
   }
}

$p = new my_class();
$p->open();

printf("%s proc hangs on fatal PHP error?\n",
   is_resource($p->proc) ? "Open" : "Not open");
non_existing_function("does not hang: just aborts");
// not reached...
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 06:01:29 2024 UTC