Php Apache杀死了长时间运行的进程

Php Apache杀死了长时间运行的进程,php,apache,ubuntu-14.04,sigkill,mod-php,Php,Apache,Ubuntu 14.04,Sigkill,Mod Php,在linux apache服务器(Ubuntu14.04 lts、带有mpm_prefork和mod_php的Apache2.4.7)上,我有需要很长时间的php脚本。这些都是被阿帕奇杀死的 我们已经调整了php设置(最大执行时间,设置时间限制…) 日志(syslog、apache访问/错误日志)中没有任何跟踪 我们使用strace跟踪了apache流程: 2172 is the script process 1939 is the apache main process .... 2172

在linux apache服务器(Ubuntu14.04 lts、带有mpm_prefork和mod_php的Apache2.4.7)上,我有需要很长时间的php脚本。这些都是被阿帕奇杀死的

我们已经调整了php设置(最大执行时间,设置时间限制…)

日志(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} ---
try set
ini\u set('max\u execution\u time',-1)

或者以root用户身份运行此脚本,则apache不会杀死他

另一种可能是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();
  }
}

我们尝试了max_execution_time-1,但结果相同。并在bash上以root用户身份运行脚本。。。脚本未被杀死。20-30分钟取决于处理Apache随机杀死脚本。2分钟,10分钟,15分钟。。。在少数情况下,脚本不会被终止:
header('Content-Type:text/html;charset=utf-8');ini_集('max_execution_time',-1);ini设置(“内存限制”,“512M”)保持活动状态是否打开?在配置中?是:在MaxKeepAliveRequests 500上保持激活(使用100测试)保持激活超时3(使用5测试)我们在while中尝试此功能:echo“
”;回显存储器的使用情况();冲洗();ob_flush()$cpt=0;这应该行得通。还可以尝试使用
set\u time\u limit(30)
,这将使脚本运行的时间增加30秒。我建议长时间运行的php脚本应该在后台运行(而不是在web服务器上),并且应该在数据库中“留下有关进度“状态”的线索。这可以通过“用户友好”的方式在web浏览器中报告。