note 20487 added to ref.exec
| From: | vi_pa at hotmail dot com | Date: | Fri, 05 Apr 2002 09:17:42 +0000 |
| Subject: | note 20487 added to ref.exec | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28648@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.
--
http://www.php.net/manual/en/ref.exec.php
http://master.php.net/manage/user-notes.php?action=edit+20487
http://master.php.net/manage/user-notes.php?action=delete+20487
http://master.php.net/manage/user-notes.php?action=reject+20487