note 102479 deleted from function.proc-open by danbrown
| From: | danbrown@php.net | Date: | Thu, 17 Feb 2011 16:18:33 +0000 |
| Subject: | note 102479 deleted from function.proc-open by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177083@lists.php.net to get a copy of this message | ||
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.