I am trying to figure out what is internally different about exec between
CLI and mod_php.
If exec() a script from CLI and said script forks, I get my prompt right
back.
test.php
<?php
exec("/home/brianm/fork.php");
?>
fork.php
#!/usr/local/bin/php
<?php
$pid = pcntl_fork();
if ($pid == -1) {
trigger_error("Could not fork FILE", E_USER_ERROR);
exit();
} elseif($pid>0) {
exit();
}
touch("/tmp/file.txt");
sleep(5);
?>
However, if I run test.php from mod_php in Apache, the parent zombies and
exec() waits for the forked process to finish.
What is the difference here and is there any hope of having exec in mod_php
work the same as it does in CLI?
Brian Moon
dealnews.com
Under apache, you inherit all of the apache sockets when the libc forks
and execs your script.
This causes some problems (there are one or two bug reports about this
in the bug db) with processes waiting around on the sockets.
It looks like there was some code in the apache SAPI to avoid this
problem, but it is currently commented out with an explanation that it
is "problematic".
I've asked about this problem a few times, but no one seems to notice my
questions or have time to reply.
So, we know of the problem, we know roughly how to fix it, but no one
can explain why we can't fix it :)
--Wez.
I am trying to figure out what is internally different about exec between
CLI and mod_php.If
exec()a script from CLI and said script forks, I get my prompt right
back.test.php
<?php
exec("/home/brianm/fork.php");
?>
fork.php
#!/usr/local/bin/php
<?php$pid =
pcntl_fork();if ($pid == -1) {
trigger_error("Could not fork FILE", E_USER_ERROR);
exit();
} elseif($pid>0) {
exit();
}touch("/tmp/file.txt");
sleep(5);?>
However, if I run test.php from mod_php in Apache, the parent zombies and
exec()waits for the forked process to finish.What is the difference here and is there any hope of having exec in mod_php
work the same as it does in CLI?Brian Moon
dealnews.com
It looks like there was some code in the apache SAPI to avoid this
problem, but it is currently commented out with an explanation that it
is "problematic".
What code exactly..? Maybe ask that who commented out why it was problematic?
--Jani
At 22:44 29/05/2003, Wez Furlong wrote:
Under apache, you inherit all of the apache sockets when the libc forks
and execs your script.This causes some problems (there are one or two bug reports about this
in the bug db) with processes waiting around on the sockets.It looks like there was some code in the apache SAPI to avoid this
problem, but it is currently commented out with an explanation that it
is "problematic".I've asked about this problem a few times, but no one seems to notice my
questions or have time to reply.So, we know of the problem, we know roughly how to fix it, but no one
can explain why we can't fix it :)
IIRC, it has to do with resources. For instance, if you close() a socket
that's used by a MySQL link, it ended up breaking the link in the parent
process. Did you try looking at the history to see whether there was any
info in the commit message?
Zeev
I think I did check, but there were no useful comments.
if close()ing them before exec'ing is a problem, can't we just set the
close-on-exec flag on the fd's ?
This will cause the descriptors to be dup'd for the fork, and the
duplicates to be closed when the child execs; in theory, that will leave
the parent in a fit and healthy state.
--Wez.
IIRC, it has to do with resources. For instance, if you close() a socket
that's used by a MySQL link, it ended up breaking the link in the parent
process. Did you try looking at the history to see whether there was any
info in the commit message?Zeev