简体   繁体   English

PHP扩展(memcache | memcached)没有在phpinfo()中显示但在php -m和php -i中显示?

[英]PHP Extension (memcache|memcached) not showing in phpinfo() but showing in php -m and php -i?

I am getting both modules listed as installed / configured when I use: 我在使用时将两个模块列为已安装/配置:

php -m

or if I use: 或者如果我使用:

php -i

but when I use: 但是当我使用时:

$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or 
$m = new Memcached;

I get the following error: 我收到以下错误:

Fatal error: Class 'Memcached' not found

I am running on a Mac - OS X (10.5.7) with default install of apache & php. 我在Mac-OS X(10.5.7)上运行,默认安装apache和php。 Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. 另外,我根据php-memcached库的要求在127.0.0.1:11211和libmemcache上运行memcached作为守护进程运行。 I have restarted apache tons of times and even done a machine restart. 我已经重启apache很多次,甚至完成了机器重启。

Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? 有谁知道为什么模块/扩展显示在命令行中而不是在我的phpinfo()中? I am literally stumped, after 3 hours of googling, I am just about ready to give up. 我真的很难过,经过3个小时的谷歌搜索,我准备放弃了。

Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file: 另外,请注意,我的phpinfo()输出我的ini文件,如下所示,它们都是完全相同的文件:

Configuration File (php.ini) Path:  /etc
Loaded Configuration File:  /private/etc/php.ini 

UPDATE: 更新:

Apache is failing to load the extension. Apache无法加载扩展。

[Fri May 14 04:22:26 2010] [warn] Init: Session Cache is not configured [hint: SSLSessionCache] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so' - (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so' - (null) in Unknown on line 0 [2010年5月14日星期五04:22:26] [warn]初始化:未配置会话缓存[提示:SSLSessionCache] PHP警告:PHP启动:无法加载动态库'/ usr / lib / php / extensions / no-debug -non-zts-20060613 / memcached.so' - (null)在第0行的Unknown中PHP警告:PHP启动:无法加载动态库'/ usr / lib / php / extensions / no-debug-non-zts-20060613 /memcache.so' - (null)在第0行的Unknown中

Does anyone know why or how this would happen? 有谁知道为什么或如何发生这种情况? Both of the files referenced above DEFINITELY ARE there. 上面引用的两个文件都在那里。 Should I move this question to server fault? 我应该将此问题移至服务器故障吗?

Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. 您的Web服务器可能正在使用mod_php,它是独立(CLI)解释器的单独代码。 If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors. 如果他们都使用相同的ini文件,并且在ini文件中配置了memcache扩展,那么听起来因为某些原因,mod_php无法加载扩展 - 检查你的webserver error_log是否有启动错误。

It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). 可能是mod_php是在没有memcache支持的情况下编译的(大多数扩展都需要将一个存根文件链接到php代码中,即使大部分代码在运行时之前都没有链接)。 Or it may be a permissions problem on the shared object file. 或者它可能是共享对象文件上的权限问题。 Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots). 或者您的网络服务器可能正在运行chroot,并且无法找到扩展名(这也意味着尽管ini文件似乎具有相同的路径,但这与不同的根相关)。

HTH HTH

C. C。

because both versions use different php.ini 因为两个版本使用不同的php.ini
place your php.ini into location noted in the phpinfo() outout 将您的php.ini放入phpinfo()outout中注明的位置

I would suspect that the issue revolves around permissions. 我怀疑这个问题围绕着权限。 When you run php from comand line, it runs as the user invoking it. 当您从命令行运行php时,它将以用户调用它的方式运行。 When run as an apache module, it runs as "nobody". 当作为apache模块运行时,它以“nobody”运行。

I would assume that the memcached.so file, or the directory it's in does not have proper permissions. 我假设memcached.so文件或它所在的目录没有适当的权限。

I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo() . 我弄明白这个帖子,并且在我的php -i中有一个扩展名但在phpinfo()没有完全相同的问题。 Mine was a permissions problem because of selinux on a CentOS machine. 由于CentOS机器上的selinux ,我的权限问题。 I had to change ownership and permissions and now it is working as expected. 我不得不更改所有权和权限,现在它按预期工作。

Set php path in environment variables as given below. 在环境变量中设置php路径,如下所示。 Right-click on "My Computer" Properties Advanced Tab > Environment Variables Under System variables, scroll down to find "Path", select and click on Edit. 右键单击“我的电脑”属性“高级”选项卡>“环境变量”在“系统”变量下,向下滚动以查找“路径”,选择并单击“编辑”。 Add path to your php install on the end (make sure to precede with semi-colon ";"). 最后添加到php安装的路径(确保以分号“;”开头)。 Example: ";C:\\php7" Click Ok. 示例:“; C:\\ php7”单击“确定”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM