note 102479 deleted from function.proc-open by danbrown

[email protected] Thu, 17 Feb 2011 08:18:33 -0800
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: aserg45 at NOSPAM yahoo -YOU KNOW- com 

----

Elaborating on what php at keith tyler dot com said on 16-Apr-2010 06:32:

Not only must you store the return value:

<?php
$proc=proc_open(....);
?>

But you must also keep it 'alive' in the current scope.
Example:

<?php
function openproc()
{
   $proc=proc_open("php -f childscript.php", array(), $tmp);
   echo "Opened process.\n";
   return TRUE;
}

openproc();
echo "The child process is running!";
?>

The first message "Opened process." will be displayed and then.....PHP will hang until the child process dies.  Because at the "return TRUE;" statement, the $proc variable (holding the return value from proc_open() ) goes out of the current scope.

Since the return value from proc_open() is no longer accessible, PHP strangely hangs.  The second message "The child process is running!" will not be displayed until AFTER the child process has terminated.

Tested with PHP 5.2.7.