PHP 在使用 finfo_file 方法时似乎遇到段错误

PHP 在使用 finfo_file 方法时似乎遇到段错误

我遇到了一个奇怪的错误。当尝试使用 Fileinfo 确定文件的 mime 类型时(http://www.php.net/manual/en/function.finfo-file.php)扩展名,PHP(或 Apache?见下文。)似乎正在崩溃。

代码:

<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE, null);
$info = finfo_file($finfo, "index.php");

从Web(通过apache2)打开时,错误日志中报告段错误:

[Wed Oct 23 14:32:25 2013] [notice] child pid 29084 exit signal Segmentation fault (11)

当从 cli 例如 执行时php -q test.php,输出没问题。

php -v
PHP 5.5.4-pl0-gentoo (cli) (built: Oct 18 2013 19:11:02)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies

/usr/sbin/apache2 -v
Server version: Apache/2.2.25 (Unix)
Server built:   Sep 20 2013 14:16:11

有什么线索吗?

答案1

你不尝试解决方案吗https://bugs.gentoo.org/show_bug.cgi?id=467756看起来也有类似的问题。

关于我如何通过将 apache2 从 mod_php 切换到 php-fpm 使用来解决该问题的一些进一步评论:

  1. 编辑 /etc/portage/package.use 并将使用标志“fpm”添加到 dev-lang/php

  2. 通过“emerge php”重新合并 php

  3. 通过“emerge mod_fastcgi_handler”安装fastcgi模块

  4. 编辑/etc/conf.d/apache2 添加“-D FASTCGI_HANDLER”并删除“-D PHP5”

  5. 编辑/etc/php/fpm-php5.4/php-fpm.conf并更改“listen”语句以通过“listen = /var/run/php-fpm.sock”使用套接字


  6. 编辑 /etc/apache2/modules.d/20_mod_fastcgi_handler.conf 并在末尾添加 AddHandler fcgi:/var/run/php-fpm.sock .php .php5 .phtml .phps DirectoryIndex index.php index.phtml

  7. 重新启动 apache 并启动 php-fpm

使用此过程切换到 php-fpm 后,apache 崩溃立即消失,我的示例脚本按预期工作。因此,我高度怀疑 mod_php 是罪魁祸首。

或者您可能需要为 apr-utils 添加 USE=nss 。

PS 显示使用标志,而不仅仅是问题程序的版本。

PPS 你别忘了给 php 添加 apache2 use 标志(默认情况下是关闭的)

相关内容