note 51772 added to ref.exec
| From: | edwardmkingatgmaildotcom at osu1 dot php dot net | Date: | Sun, 10 Apr 2005 22:39:42 +0000 |
| Subject: | note 51772 added to ref.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-87799@lists.php.net to get a copy of this message | ||
So it seems that a lot of people are trying to running bash commands in the background from php. Me
too.
"margus at kohv dot com" posted a note about using perl to fork and exit. I messed around
a little and came up with this. It seems to work really well.
function exec_background ($cmd)
{
exec("echo 'fork and exit 1; system(\"$cmd\");' | perl
>/dev/null");
}
I pu:t this in a .inc file and do a require() when I use it. The function can then be called as
such:
<?
exec_background("ssh FQDN reboot");
?>
Note: (obviously) this is for linux (possibly other unices). The command will be executed with the
permissions of the user who started apache (I think). Also note that you wont get any output from
the command (but then again, you wouldn't really expect any).
For Windows:
this is a little more involved. First, reboot your computer into dos-mode. At the command-line,
type:
format c:
and install a real operating system.
----
Manual Page -- http://www.php.net/manual/en/ref.exec.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51772
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51772&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51772&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51772&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51772&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51772&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51772&report=yes
Search -- http://master.php.net/manage/user-notes.php