随机的“;PHP致命错误:内存不足;错误


Random "PHP Fatal error: Out of memory" errors

由于我将一个PHP应用程序移到了一个新服务器上(PHP/5.3.8在32位Windows server 2003 R2上作为Apache 2.2模块运行),我在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(因此524288字节应该不是问题)。

  3. 在报告的行中,通常有一些非常无辜的代码,比如函数定义的开头。。。

    function linea($html){
    

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

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

我想我已经放弃了所有显而易见的东西(我甚至在硬盘中的所有*.php、*.ini、.htaccess和*.conf文件中搜索了memory_limit字符串),并且我已经编写了检测和记录"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)

其中系统错误8映射到:

ERROR_NOT_ENOUGH_MEMORY 8 (0x8)存储空间不足,无法处理此命令。

我刚刚在PHP树中快速搜索了"内存不足",发现如果内部分配调用(例如malloc)失败,Zend内存管理器会触发此错误(请参阅代码)。

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