Php

zend_mm_heap 損壞的 PHP 致命錯誤:無法重新聲明 composerRequire

  • December 13, 2018

我們有一個網路伺服器,除了正常的請求外,還會上傳大文件。

一些請求(例如 1/10)被丟棄。我們在錯誤日誌中看到以下錯誤。

==> /var/log/apache2/web_error_ssl.log <==
[Fri Dec 07 15:38:24.154218 2018] [php7:error] [pid 8333] [client ****:****:****:****:216:3eff:fe0b:bb4f:55760] PHP Fatal error:  Cannot redeclare composerRequire2f3df4313599c81c8cd86cade0406e0b() (previously declared in /var/www/releases/test/vendor/composer/autoload_real.php:54) in /var/www/releases/test/vendor/composer/autoload_real.php on line 61

==> /var/log/apache2/error.log <==
[Fri Dec 07 15:38:24.385423 2018] [core:notice] [pid 18418] AH00052: child pid 8333 exit signal Segmentation fault (11)

==> /var/log/apache2/web_error_ssl.log <==
[Fri Dec 07 15:38:27.243422 2018] [php7:error] [pid 8318] [client ****:****:****:****:216:3eff:fe0b:bb4f:56308] PHP Fatal error:  Cannot redeclare composerRequire2f3df4313599c81c8cd86cade0406e0b() (previously declared in /var/www/releases/test/vendor/composer/autoload_real.php:54) in /var/www/releases/test/vendor/composer/autoload_real.php on line 61

==> /var/log/apache2/error.log <==
zend_mm_heap corrupted

環境:

更新了 debian 拉伸

Apache 版本:2.4.25-3+deb9u6,帶有 prefork mpm。

PHP版本:7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd(來自sury儲存庫)

PHP 作為 apache2 模組載入。

到目前為止,我們已經測試過:

  • opcache.enable = 0 / 1
  • opcache.enable_cli = 0 / 1
  • output_buffering = 關閉 / 4096 / 16777216
  • realpath_cache_size = 0 / 4096k
  • 替換幾個版本的 PHP7.0 和 PHP7.1(來自 debian repo 和 sury repo)
  • index.php: 定義(‘HHVM_VERSION’, ?); ? =真/假
  • /etc/apache2/envvars: 導出 USE_ZEND_ALLOC = 0 / 1
  • 切換到反向移植核心

幫助我們的是網路伺服器重新載入 - 它解決了幾分鐘的問題,然後重新開始。

當我們捕捉到失敗的程序時,我們得到:

open("/var/www/releases/test/vendor/composer/autoload_real.php", O_RDONLY) = 17
fstat(17, {st_mode=S_IFREG|0644, st_size=2103, ...}) = 0
fstat(17, {st_mode=S_IFREG|0644, st_size=2103, ...}) = 0
fstat(17, {st_mode=S_IFREG|0644, st_size=2103, ...}) = 0
fstat(17, {st_mode=S_IFREG|0644, st_size=2103, ...}) = 0
mmap(NULL, 2103, PROT_READ, MAP_SHARED, 17, 0) = 0x7f61c3186000
getpid()                                = 21075
getpid()                                = 21075
getpid()                                = 21075
write(12, "[Thu Dec 06 23:58:59.246179 2018] [php7:error] [pid 21075] [client ****:****:****:****::aaaa:1:31248] PHP Fatal error:  Cannot redeclare composerRequire2f3df4313599c81c8cd86cade0406e0b() (previously declared in /var/www/releases/test/vendor/composer/autoload_real.php:54) in /var/www/releases/test/vendor/composer/autoload_real.php on line 61\n", 348) = 348
chdir("/")                              = 0
munmap(0x7f61ab800000, 16781312)        = 0
setitimer(ITIMER_PROF, {it_interval={tv_sec=0, tv_usec=0}, it_value={tv_sec=0, tv_usec=0}}, NULL) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x7f61adfbae68} ---

autoload_real.php 包含的文件是由

composer install --no-progress --prefer-dist --no-dev --classmap-authoritative

第 54 - 61 行如下:

function composerRequire2f3df4313599c81c8cd86cade0406e0b($fileIdentifier, $file)
{
   if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
       require $file;

       $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
   }
}

PHP 模組列表:

root@server:~# dpkg -l | grep php7.1
ii  libapache2-mod-php7.1             7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php7.1-bcmath                     7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        Bcmath module for PHP
ii  php7.1-cli                        7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        command-line interpreter for the PHP scripting language
ii  php7.1-common                     7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        documentation, examples and common module for PHP
ii  php7.1-curl                       7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        CURL module for PHP
ii  php7.1-gd                         7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        GD module for PHP
ii  php7.1-json                       7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        JSON module for PHP
ii  php7.1-mbstring                   7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        MBSTRING module for PHP
ii  php7.1-mysql                      7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        MySQL module for PHP
ii  php7.1-opcache                    7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        Zend OpCache module for PHP
ii  php7.1-readline                   7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        readline module for PHP
ii  php7.1-sqlite3                    7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        SQLite3 module for PHP
ii  php7.1-xml                        7.1.24-1+0~20181112093455.10+stretch~1.gbp09a4fd      amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP

所以經過幾天的測試,我們發現升級到 PHP 7.2 可以解決我們的問題。

引用自:https://serverfault.com/questions/943327