zend_mm_heap 损坏 PHP 致命错误:无法重新声明 composerRequire

zend_mm_heap 损坏 PHP 致命错误:无法重新声明 composerRequire

我们有一个网络服务器,除了正常请求外,还上传大文件。

一些请求(例如 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 Strel

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
  • 输出缓冲 = 关闭 / 4096 / 16777216
  • realpath_cache_size = 0 / 4096k
  • 替换多个版本的 PHP7.0 和 PHP7.1(来自 debian repo 和来自 sury repo)
  • index.php:define('HHVM_VERSION',?);?= true/false
  • /etc/apache2/envvars:导出 USE_ZEND_ALLOC = 0/1
  • 切换到反向移植内核

对我们有帮助的是网络服务器重新加载——它可以在几分钟内解决问题,然后重新启动。

当我们捕获失败进程的 strace 时,我们得到:

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

答案1

因此经过几天的测试,我们发现升级到 PHP 7.2 可以解决我们的问题。

相关内容