note 118495 added to function.shell-exec
| From: | alexandre dot schmidt at gmail dot com | Date: | Wed, 16 Dec 2015 02:26:09 +0000 |
| Subject: | note 118495 added to function.shell-exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204381@lists.php.net to get a copy of this message | ||
To run a command in background, the output must be redirected to /dev/null. This is written in
exec() manual page. There are cases where you need the output to be logged somewhere else though.
Redirecting the output to a file like this didn't work for me:
<?php
# this doesn't work!
shell_exec("my_script.sh 2>&1 >> /tmp/mylog &");
?>
Using the above command still hangs web browser request.
Seems like you have to add exactly "/dev/null" to the command line. For instance, this
worked:
<?php
# works, but output is lost
shell_exec("my_script.sh 2>/dev/null >/dev/null &");
?>
But I wanted the output, so I used this:
<?php
shell_exec("my_script.sh 2>&1 | tee -a /tmp/mylog 2>/dev/null >/dev/null
&");
?>
Hope this helps someone.
----
Server IP: 72.52.91.14
Probable Submitter: 189.30.193.215
----
Manual Page -- http://php.net/manual/en/function.shell-exec.php
Edit -- https://master.php.net/note/edit/118495
Del: integrated -- https://master.php.net/note/delete/118495/integrated
Del: useless -- https://master.php.net/note/delete/118495/useless
Del: bad code -- https://master.php.net/note/delete/118495/bad+code
Del: spam -- https://master.php.net/note/delete/118495/spam
Del: non-english -- https://master.php.net/note/delete/118495/non-english
Del: in docs -- https://master.php.net/note/delete/118495/in+docs
Del: other reasons-- https://master.php.net/note/delete/118495
Reject -- https://master.php.net/note/reject/118495
Search -- https://master.php.net/manage/user-notes.php