So I have a problem where passthru doesn't seem to be handling the ulimit as expected on Centos.
My php is simply:
<?php
echo "<pre>";
passthru('/bin/myscript.sh',$return_code);
echo "<br>";
echo "Got $return_code as always";
echo "</pre>";
?>
The bash is simply:
#!/bin/bash
bail()
{
echo "File too large detected via signal."
exit 12
}
trap bail SIGXFSZ
# set max wirte size to 2.1 MB
ulimit -f 2100
# check that it's set
ulimit -a
# see we're ok
# file size (blocks, -f) 2100
cp /path/5mb_file /path/5mb_file.cp
LOCALRET=$?
# return code = 128+SIGXFSZ = 153 (on my Centos anyway)
if [[ ${LOCALRET} -eq 153 ]]; then
echo "File too large detected via return code"
else
echo "Got ${LOCALRET}"
fi
exit 0
If I run myscript.sh at the bash command line, I get a nice "File too large detected via return code" show up and 2.1 MB of the 5 MB file copied. So I assume the cp child process caught and handled the SIGXFSZ signal and there is nothing for the parent myscript.sh to catch.
But when I run the PHP script while the o/s stops the cp at 2.1 MB, ${LOCALRET} is 1 (of course I also see the "Got 0 as always" message as myscript.sh always returns 0). Somehow the child of myscript.sh isn't getting the signal properly it seems. In fact if it's a more elaborate process than a cp, it will not stop the process -- The process appears not to have gotten the signal (of course the o/s won't let it write more than 2.1 MB but it seems to be obvious to the signal).
Interesting side note here that is probably related is the if I'm on MacOS (running same PHP 5.3.3 with Apache 2) the signals seem to work correctly. So am I misunderstanding something here? Is there a compile setting in PHP to make the Centos behave like the MacOS for signals (like --enable-sysvmsg or such)?? Right now it's just:
./configure --with-mysqli --with-zlib --with-xml --with-mysql --with-openssl --enable-sockets --enable-calendar --with-curl --with-apxs2
Thanks in advance!!