.php scripts running more than max_execution_time

P

postcd

Guest
Hello,

on my webserver (Apache, php) i have like 32 seconds max execution time, but my firewall (config server firewall) reporting processes that running more than 100 seconds. I want to ask why these processes are not killed by apache after 32 seconds from execution? Can i anyhow change this using free software/tools? Why actually there is above mentioned php variable while scripts running longer than that?

i found also an Apache directive called "Timeout"
 
Last edited:


I never saw apache or php timeouts working properly. Apache has a module named reqtimeout that could be help you to fix your execution time.
 
I never saw apache or php timeouts working properly. Apache has a module named reqtimeout that could be help you to fix your execution time.
Thx for an advice, i see i already have it installed:
# httpd -M | grep time
Syntax OK
reqtimeout_module (shared)

my virtualhost config is:
<IfModule mod_reqtimeout.c>
RequestReadTimeout header=20-40,MinRate=500 body=20-40,MinRate=500
</IfModule>

i installed it according to this manual. Please any idea to tweak the confirguration for the processes to be really killed/timeout?
 
It depends on where is the waiting section. I assumed that your script runs too long with some outside proces calls or with mysql execution which not handled by max_execution_time.

Here is the two possible waiting situations on php;

max_execution_time working on this
while(1);

max_execution_time not working because its not handled by php
sleep(30);


If second situation is your case you should use php with fastcgi or other modules that does not integrated with apache. Installing fastcgi and configurations is not so easy.

Instead of you can use this code snippets in the top of your php file.

PHP:
  function signal_handler($signal) {
    die("Timeout");
  }

  pcntl_signal(SIGALRM, "signal_handler", true);
  pcntl_alarm(30);

But here is the deal, pcntl disabled on default on apache environment. You should install from source of pcntl module and enable it from php config.
Code:
apt-get install php5-dev dpkg-dev

mkdir tmp/phpsrc
cd /tmp/phpsrc
apt-get source php5
cd /tmp/phpsrc/php5-*/ext/pcntl
phpize
./configure
make

cp modules/pcntl.so /usr/lib/php5/some_date_here/
echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini
php5enmod pcntl


disable this line from your php config by putting ; on the begining


on debian its in
/etc/php5/apache2/php.ini

disable_functions =     pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority


service apache2 restart

You also need to work out why it takes so long to execute. 100 seconds means that your script or query cant be handled.
 


Top