Reputation: 1147
I can't seem to use system() to create a long lasting, forked process: (yes, params are OK)
$args = "/code/perl/test/run $a $n $m $s $c &";
system($args);
But, on the flipside this code DOES work, but it doesn't have parameters:
system("/code/perl/test/reset &");
So, the problem? My C program "run" is instantly killed with the finishing of the PHP script from the HTTP request.
I have tried using the at daemon to create the process using a seperate parent process, but with no success. www-data was removed from /etc/at.deny
It's worth noting that with the 2nd example I do get program output, but not on the first.
Upvotes: 0
Views: 247
Reputation: 1147
This is a result of the PHP script finishing, then killing all child processes attached to it.
If the "at" workaround doesn't work (where you use atd to schedule it for "now"), like it didn't for me, you may have to code a workaround. My workaround just put the command in a file in /tmp/ and then I had my daemon's code execute the commands in the file, then truncated it.
Upvotes: 0
Reputation: 8817
From the docs:
If a program is started in this fashion, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
Therefore, if it's ending immediately, it most likely does not appear run
is being ran. Try sending the output to a different file. Try: exec("/bin/echo $a $n $m $s $c > /tmp/echo &");
to start diagnostics.
After that, I would check for safe_mode and try escapeshellcmd
. As a last resort, try the backtick `
operator.
Upvotes: 1