2012-01-10 166 views
9

由于我将PHP应用程序移动到新服务器(在32位Windows Server 2003 R2上作为Apache 2.2模块运行的PHP/5.3.8),我收到了随机错误在PHP错误日志:随机“PHP致命错误:内存不足”错误

[09-Jan-2012 19:45:12] PHP Fatal error: Out of memory (allocated 786432) (tried to allocate 17 bytes) in D:\site\util\odbc-connection.php on line 675 
[10-Jan-2012 17:56:49] PHP Fatal error: Out of memory (allocated 1310720) (tried to allocate 6144 bytes) in D:\site\logic\data.php on line 630 
[10-Jan-2012 17:58:52] PHP Fatal error: Out of memory (allocated 524288) (tried to allocate 393216 bytes) in D:\site\users\edit-user.php on line 458 

我很困惑,原因如下:

  1. 这是当达到memory_limit你得到标准的错误消息:

    Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 800001 bytes) 
    
  2. 无论如何,memory_limit默认为256MB在服务器上,并在此应用程序上设置为128MB(因此524,288字节应该不成问题)。

  3. 在报告行有常很无辜的代码,如函数定义开始......

    function linea($html){ 
    

    ...或的foreach()循环非常小的数组:

    foreach($perfiles_basicos as $c => $v){ 
    

我想我已经丢弃了所有明显的东西(我甚至在硬盘中搜索了所有* .php,* .ini,.htaccess和* .conf文件中的memory_limit字符串)和I 'w w ritten代码来检测和记录“128MB”限制的变化(没有发现任何东西),所以我现在很无能。

任何暗示或想法?


更新#1: Apache的error.log显示我得到一个内存不足错误从PHP之后,Web服务器被重新启动。有些是手动重新启动,有些则崩溃这样的:

zend_mm_heap corrupted 
12] [notice] Child 2524: Child process is exiting 
[Mon Jan 09 19:45:12 2012] [notice] Parent: child process exited with status 1 -- Restarting. 
[Mon Jan 09 19:45:13 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366) 
[Mon Jan 09 19:45:13 2012] [notice] Apache/2.2.21 (Win32) mod_ssl/2.2.21 OpenSSL/1.0.0e PHP/5.3.8 configured -- resuming normal operations 
[Mon Jan 09 19:45:13 2012] [notice] Server built: Sep 24 2011 00:32:50 
[Mon Jan 09 19:45:13 2012] [notice] Parent: Created child process 6256 
[Mon Jan 09 19:45:13 2012] [notice] Disabled use of AcceptEx() WinSock2 API 
[Mon Jan 09 19:45:13 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366) 
[Mon Jan 09 19:45:14 2012] [warn] Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366) 
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Child process is running 
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Acquired the start mutex. 
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Starting 400 worker threads. 
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Listening on port 443. 
[Mon Jan 09 19:45:14 2012] [notice] Child 6256: Listening on port 80. 

更新#2: ...和ODBC扩展日志记录以下错误:

No se puede cargar el controlador especificado debido al error del sistema 8 (Oracle in instantclient_11_2) 

...其中system error 8地图到:

ERROR_NOT_ENOUGH_MEMORY 8 (0x8) Not enough storage is available to process this command.

+0

你使用任何框架? – Gerep 2012-01-10 18:07:19

+3

您是否检查了系统上的内存使用情况? OOM通常在系统无法物理分配内存时发生,而不是在PHP达到了对请求的限制时。 – 2012-01-10 18:08:37

+0

没有框架,只是香草PHP。我会尝试监视系统的内存。 – 2012-01-11 08:18:36

回答

8

我只是在PHP树中快速搜索“内存不足”,发现这个错误是由Zend内存管理器如果内部分配呼叫(例如, malloc)失败(see code)。

所以,是的,听起来像系统内存不足;)

+0

是的,这是我甚至没有考虑过的简单而明智的解释。目前,服务器几乎处于空闲状态,任务管理器显示具有极高虚拟内存使用率的“wmicpa.exe”进程。我最好问问系统管理员。 – 2012-01-11 08:17:44

+0

我仍然不知道错误的确切原因,但是您的答案和Apache错误日志中的“zend_mm_heap已损坏”消息指出了某些内存分配问题,这些问题超出了我的范围。 – 2012-01-20 09:10:49