如何追踪 PHP 崩溃


How to track down PHP crashes?

我正在尝试追踪Apache PHP崩溃的原因。 我希望有某种设置,工具或其他东西可以帮助跟踪导致这些php崩溃的代码,配置或问题所在。

在我的 Windows 事件日志中,我有(显示 apache 崩溃,但由 php 引起):

Faulting application httpd.exe, version 2.2.21.0, time stamp 0x4e6b3136, faulting module php5ts.dll, version 5.3.8.0, time stamp 0x4e537a04, exception code 0xc0000005, fault offset 0x0000c7d7, process id 0xbf4, application start time 0x01cd45afc42f0b7d.

该应用程序在Windows Server 2008机器(xampp)上使用Apache,PHP和MySQL。

这是我的Apache日志中的崩溃:

[Fri Jun 08 15:56:34 2012] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Fri Jun 08 15:56:35 2012] [notice] Digest: generating secret for digest authentication ...
[Fri Jun 08 15:56:35 2012] [notice] Digest: done
[Fri Jun 08 15:56:35 2012] [notice] Apache/2.2.21 (Win32) PHP/5.3.8 configured -- resuming normal operations
[Fri Jun 08 15:56:35 2012] [notice] Server built: Sep 10 2011 11:34:11
[Fri Jun 08 15:56:35 2012] [notice] Parent: Created child process 1220
[Fri Jun 08 15:56:35 2012] [notice] Digest: generating secret for digest authentication ...
[Fri Jun 08 15:56:35 2012] [notice] Digest: done
[Fri Jun 08 15:56:35 2012] [notice] Child 1220: Child process is running
[Fri Jun 08 15:56:35 2012] [notice] Child 1220: Acquired the start mutex.
[Fri Jun 08 15:56:35 2012] [notice] Child 1220: Starting 150 worker threads.
[Fri Jun 08 15:56:35 2012] [notice] Child 1220: Starting thread to listen on port 80.
[Fri Jun 08 15:56:35 2012] [notice] Child 1220: Starting thread to listen on port 80.
[Fri Jun 08 15:57:37 2012] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Fri Jun 08 15:57:37 2012] [notice] Digest: generating secret for digest authentication ...
[Fri Jun 08 15:57:37 2012] [notice] Digest: done
[Fri Jun 08 15:57:37 2012] [notice] Apache/2.2.21 (Win32) PHP/5.3.8 configured -- resuming normal operations
[Fri Jun 08 15:57:37 2012] [notice] Server built: Sep 10 2011 11:34:11
[Fri Jun 08 15:57:37 2012] [notice] Parent: Created child process 3932
[Fri Jun 08 15:57:38 2012] [notice] Digest: generating secret for digest authentication ...
[Fri Jun 08 15:57:38 2012] [notice] Digest: done
[Fri Jun 08 15:57:38 2012] [notice] Child 3932: Child process is running
[Fri Jun 08 15:57:38 2012] [notice] Child 3932: Acquired the start mutex.
[Fri Jun 08 15:57:38 2012] [notice] Child 3932: Starting 150 worker threads.
[Fri Jun 08 15:57:38 2012] [notice] Child 3932: Starting thread to listen on port 80.
[Fri Jun 08 15:57:38 2012] [notice] Child 3932: Starting thread to listen on port 80.

关于我应该尝试什么的任何想法,或者追溯到什么代码的工具/技术等可能导致这种情况?

由于 XAMPP 的 Apache(适用于 Windows)是用 MPM(多线程)+ 线程安全 PHP 构建winn_nt,因此您可能遇到了所谓的线程安全版本的 PHP 固有的问题(有关更多信息,请参阅这篇非常好的文章)。这可以解释为什么在单用户模式下运行时永远不会遇到错误。

请让我们知道Uku Loskit的建议是否有任何好处。如果没有,我建议在这样的多用户环境中切换到Prefork +非线程安全的PHP设置。

由于必须在编译时选择 MPM,因此您需要:

  • 自己编译 Apache(技术上可行,但据我所知,在 Windows 上很痛苦)
  • 找到 XAMPP 以外的发行版,它是用 prefork 构建的(我不知道)

也许你最好尝试用FastCGI运行PHP(这个额外的层基本上通过为每个线程启动一个单独的PHP进程来隔离服务器线程,等等)。这应该可以让您轻松验证我的初始假设。

附带说明一下:我不认为在Windows服务器上安装Apache有什么意义。您可能需要考虑使用 IIS,也可以选择使用 FastGCI(请参阅此处的说明),或者(更好地)切换到基于 Linux 的堆栈。