note 20468 deleted from ref.exec by goba
| From: | goba@php.net | Date: | Tue, 20 Aug 2002 08:11:00 +0000 |
| Subject: | note 20468 deleted from ref.exec by goba | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-35237@lists.php.net to get a copy of this message | ||
For those who want to execute a .php script to run in the background, from a .php web page...
exec("php script.php parameters 2>dev/null >&- <&- >/dev/null &");
Where...
- php is the path to your php script executer (php has to be specifically complied to be to do this)
- script.php is the script
- parameters are none or more parameters
- 2>dev/null redirects the stderr to a file
- <&- switches off the stdin
- >&- switches off the stdout
- >dev/null redirects all other output to the file dev/null
- & direct script to run in background
This is the only way I managed to get it working (Linux & Apache, php 4x enviroment) . What is
also great is that the process is forked so even though a user may close the browser that initiated
the exec(), the process will still run to completion. And the dev/null file can be turned into a
log.
What I found odd is that the script I was execing would run fine in the bg when executed from the
command line, but not from the browser until I closed the stdin and stdout. Any insight into this?