note 59884 added to function.system
| From: | 151408626 dot unique at servux dot org | Date: | Mon, 19 Dec 2005 10:56:49 +0000 |
| Subject: | note 59884 added to function.system | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-100401@lists.php.net to get a copy of this message | ||
The documentation notes that for making a program running in the background: ... you have to make
sure that the output of that program is redirected to a file or some other output stream ...
But simply redirecting the command's output to a fifo will also cause PHP to wait for the
command to terminate, even if it is started in background.
After quite a bit of trial & error, however I figured out that the trick (mentioned in some
other note) using parenthesis to regain control over an already redirected STDOUT does work here,
too:
<?
// this will not execute the echo in background while continuing the PHP-script,
// as one might expect
system("echo 'something' >$someFIFO &");
// however that will do the trick - the echo is run in background, waiting until the data is read
// from the FIFO, while your PHP-script continues execution, e.g. being able to open that
// FIFO for read without being blocked until some data will arrive!!
system("(echo 'something' >$someFIFO) >/dev/null &");
?>
----
Manual Page -- http://www.php.net/manual/en/function.system.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+59884
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59884&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59884&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59884&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59884&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59884&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59884&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59884&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+59884&report=yes
Search -- http://master.php.net/manage/user-notes.php