note 51772 deleted from ref.exec by nlopess
| From: | nlopess@php.net | Date: | Mon, 11 Apr 2005 14:14:32 +0000 |
| Subject: | note 51772 deleted from ref.exec by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-87835@lists.php.net to get a copy of this message | ||
Note Submitter: edwardmking at gmail dot com
----
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.