1

在 linux apache 服务器(ubuntu 14.04 lts,带有 mpm_prefork 和 mod_php 的 apache 2.4.7)上,我的 PHP 脚本需要很长时间。这些被apache杀死了。

我们调整了 php 设置 (max_execution_time, set_time_limit...)

我们在日志中没有任何跟踪(syslog、apache 访问/错误日志)

我们使用 strace 跟踪了 apache 进程:

2172 is the script process
1939 is the apache main process
....

2172  14:53:01 +++ killed by SIGKILL +++
1939  14:53:01 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=2172, si_status=SIGKILL, si_utime=3067, si_stime=38} ---
4

2 回答 2

1

尝试ini_set('max_execution_time', -1); 以root身份设置或运行此脚本,然后apache不会杀死他

于 2014-10-01T15:20:26.950 回答
0

另一种可能性是 Apache2 正在杀死该进程,因为它在一定时间内没有发回任何东西。这通常发生在共享主机上。如果您正在使用输出缓冲,请将其关闭。然后每隔一段时间打印出一些东西并立即用于flush()将信息发送回Apache。

例如; 在最长的循环中,您可以执行以下操作:

$time = time();
while($looping) {
  ... Code here ...
  if(time() > $time) {
    echo '.';
    flush();
    //ob_flush();//If you're using output buffering (often on by default)
    $time = time();
  }
}
于 2014-10-01T15:36:42.510 回答