exec, passthru, or backticks won't fork?
| From: | Zachary Hamm | Date: | Mon, 21 Aug 2000 22:23:20 +0000 |
| Subject: | exec, passthru, or backticks won't fork? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-12825@lists.php.net to get a copy of this message | ||
Using PHP 3.0.16 on Apache 1.3.9 on Linux.
I'm trying to run a rather long program in the background when a user
selects it from a webpage (kind of a "start this import program
manually" page) for users to do a database import. The import can take
up to several hours to run, so it's impractical for the process to tie
up the browser in the foreground.
I can't seem to find a way to fork this huge process in the background
and let it go it's merry way.
I did find on php.net a C wrapper which supposedly supports this, and
indeed it works, but not entirely (not sure why, since I know jack about
C), as the process seems to die off midway (buffer overflow perhaps?).
The cron job shown below is actually a perl script which does a huge
import from a remote text file (using rsh) and imports locally to Mysql.
Anyway, here's the code:
<?
# using a call to a C program called "fork" which forks process in bg.
# uncommenting #2# below would run it, with output to page.
if ($submit) {
exec("fork /etc/cron.daily/carma.cron & 2>&1");
#2#exec("/etc/cron.daily/carma.cron &");
}
And the C code that I stole which doesn't QUITE work:
/* fork.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int pid;
pid=fork();
if (pid!=0)
{
close(STDOUT_FILENO);
close(STDIN_FILENO);
close(STDERR_FILENO);
execl(argv[1],argv[2],0);
}
return 0;
}
Please tell me what I'm missing.
Thanks in advance...