PHP 警告:模块“mcrypt”已加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21923534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 04:32:29  来源:igfitidea点击:

PHP warning : Module 'mcrypt' already loaded

phpubuntu-12.10

提问by Zied R.

When I run a command with PHP, it shows me an error. E.g when I run php -vto see my PHP-version it shows me an error then the informations about PHP:

当我用 PHP 运行命令时,它显示一个错误。例如,当我运行php -v查看我的 PHP 版本时,它显示一个错误,然后显示有关 PHP 的信息:

Module 'mcrypt' already loaded in Unknown on line 0

模块“mcrypt”已在第 0 行的 Unknown 中加载

zied@ubuntu:~$ php -v

PHP Warning:  Module 'mcrypt' already loaded in Unknown on line 0

PHP 5.4.25-1+sury.org~quantal+2 (cli) (built: Feb 12 2014 11:11:30) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

回答by Martin Tournoij

Your php.inicontains two or more of these lines:

您的php.ini包含以下两行或更多行:

extension=mcrypt.so

Remove all except one.

除一个之外的所有删除。

php.iniusually lives in /etc/php.inior /etc/php5/php.ini. Sometimes additional .ini files are included, you can see all of them with:

php.ini通常住在/etc/php.ini/etc/php5/php.ini。有时包含额外的 .ini 文件,您可以通过以下方式查看所有文件:

$ php -i | grep .ini$
Loaded Configuration File => /usr/local/etc/php.ini
Additional .ini files parsed => /usr/local/etc/php/extensions.ini
user_ini.filename => .user.ini => .user.ini

回答by drookie

Sometimes this happens with php-fpm, and the funny thing is, console phpdoesn't complans about this using the same set of .ini-files in the same time, proving that mcryptin fact isn't referenced twice.

有时会发生这种情况php-fpm,有趣的是,控制台php不会同时使用相同的 .ini 文件集来解决这个问题,这证明mcrypt实际上没有被引用两次。

As it turns out, php-fpmhas a default set of modules built-in that it's trying to load, at least on Linux (since that isn't reproducible on FreeBSD). mcryptis in this list, so when a user has an additional .ini-file in it's /etc/php.ddirectory, mcryptseems to be loaded twice.

事实证明,它php-fpm有一组默认的内置模块,它试图加载,至少在 Linux 上是这样(因为在 FreeBSD 上无法重现)。mcrypt在这个列表中,所以当用户在它的/etc/php.d目录中有一个额外的 .ini 文件时,mcrypt似乎被加载了两次。

A harsh workaround for this is to add the -nswitch to the php-fpm on the start, copy pnp.inito a php-fpm.ini, include all of your modules into the resulting php-fpm.iniexcept mcryptand add an additional switch pointing at the correct ini-file, so the whole addition looks like: -n -c /etc/php-fpm.ini.

一个苛刻的解决方法是在开始时将-n开关添加到 php-fpm,复制pnp.ini到 a php-fpm.ini,将所有模块包含到结果中,php-fpm.ini除了 mcrypt并添加一个指向正确 ini 文件的附加开关,因此整个添加看起来像:-n -c /etc/php-fpm.ini

This way running php-fpmwon't complain.

这样跑步php-fpm就不会抱怨了。

I'm writing this here, because this is most referenced post in search engines about mcryptissue. I realize the source question was about console php.

我在这里写这个,因为这是搜索引擎中关于mcrypt问题的最常引用的帖子。我意识到源问题是关于控制台 php。

Update:I was using this workaround, but it is nasty. Some time ago I have figured out exactly why did this happen. I'll spend some more words to describe this, but this can be boring, since this will describe a certain type of failure. So, in my case this issue was caused by the fact, that I was using a custom php build, made by myself, and occasionally I've added the mcryptto the list of builtin staticmodules. And thenI added it again as a built module, so it was loaded twice. This happens with a custom build when mcryptis referenced in the list of modules for the configure script, and isn't listed as shared(this part of the spec can be easily found, since %configure \is mentioned only once in the spec). In my case the solution was to remove the mcryptentirely from the configure part, and add it to the build-cgiand build-ztsclistages. One could ask " What about the fpm stage ?"- and it's a good question, but, it turns out, fpmsapi itself is built with a minimum of modules and uses generic sharedones.

更新:我正在使用此解决方法,但它很糟糕。前段时间我已经弄清楚为什么会发生这种情况。我会多花一些词来描述这个,但这可能很无聊,因为这将描述某种类型的失败。因此,在我的情况下,这个问题是由以下事实引起的,即我使用的是自己制作的自定义 php 版本,并且偶尔我将mcrypt添加到内置静态模块列表中。而随后我又增加一条,作为一个内置模块,因此它被加载两次。当在配置脚本的模块列表中引用mcrypt并且未列为共享时,自定义构建会发生这种情况(规范的这一部分很容易找到,因为%configure \在规范中只提到一次)。在我的情况下,解决方案是从配置部分完全删除mcrypt,并将其添加到build-cgibuild-ztscli阶段。有人可能会问“fpm 阶段呢?” - 这是一个很好的问题,但事实证明,fpmsapi 本身是用最少的模块构建的,并使用通用的共享模块。

回答by W.M.

I had the same issue and it was due to building PHP from source with ./configure --with-mcryptoption. It seems that if PHP is built with the --with-mcryptflag, then there is no need to specify extension=mcrypt.soin php.ini. Doing so causes the warning mentioned above.

我遇到了同样的问题,这是由于使用./configure --with-mcrypt选项从源代码构建 PHP 。好像PHP是用--with-mcryptflag构建的,那么就不用extension=mcrypt.sophp.ini. 这样做会导致上述警告。