在命令行 PHP 脚本中找不到“Memcache”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1171313/
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 01:19:30  来源:igfitidea点击:

'Memcache' not found in command line PHP script

phpapachecommand-linememcached

提问by Richard Stelling

I have Memcache installed and working for PHP apps run through Apache (v2.2) but when I try to run a .php file in the command-line i get this error:

我安装了 Memcache 并为通过 Apache (v2.2) 运行的 PHP 应用程序工作,但是当我尝试在命令行中运行 .php 文件时,我收到此错误:

Fatal error: Class 'Memcache' not found in /usr/local/Matters/app/matters-common/connection.php on line 94

Line 94 is:

第 94 行是:

$memcache = new Memcache;

Other info:

其他信息:

CentOS 5.2
PHP 5.2.5 (cli) (built: Feb 20 2008 21:13:12)
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
Apache v2.2.8

CentOS 5.2
PHP 5.2.5 (cli)(构建时间:2008 年 2 月 20 日 21:13:12)
Zend Engine v2.2.0,版权所有 (c) 1998-2007 Zend Technologies
Apache v2.2.8

回答by John Carter

Presumably you have separate php.ini files set up for apache and the command line (cli).

大概您为 apache 和命令行 (cli) 设置了单独的 php.ini 文件。

If so, you need to add the following to your cli php.ini file:

如果是这样,您需要将以下内容添加到您的 cli php.ini 文件中:

extension=memcache.so

On Ubuntu it's in /etc/php5/cli/php.ini

在 Ubuntu 上,它位于 /etc/php5/cli/php.ini

If it's working then memcache should appear in the list of modules if you run php -mon the command line.

如果它正常工作,那么如果您php -m在命令行上运行,内存缓存应该出现在模块列表中。

Alternatively, you can create a file /etc/php5/cond.d/memcache.iniwith the same contents.

或者,您可以创建/etc/php5/cond.d/memcache.ini具有相同内容的文件。

回答by leafnode

It is possible that you have a separate php.ini file for CLI mode. This file might not include memcache extension.

您可能有一个单独的 php.ini 文件用于 CLI 模式。此文件可能不包含内存缓存扩展名。

回答by Joemarie Aliling

I did have this kind of error and I also did php -i | grep memcache and it says memcache is enabled, but my solution that solved the problem was when I edited the php.ini, i simply modified the extension_dir="./" line to the full path of the extensions directory which now looked like this, extension_dir="/usr/local/lib" -- you need to check where the extension directory of the php reside and make sure memcache.so is there..

我确实有这种错误,我也做了 php -i | grep memcache 并且它说 memcache 已启用,但是我解决问题的解决方案是当我编辑 php.ini 时,我只是将 extension_dir="./" 行修改为 extensions 目录的完整路径,现在看起来像这样, extension_dir="/usr/local/lib" -- 您需要检查 php 的扩展目录所在的位置,并确保 memcache.so 在那里..

then i simply restarted httpd and alas the problem is gone.

然后我只是重新启动了 httpd,唉,问题就消失了。

you can check the detailed steps here:

您可以在此处查看详细步骤:

http://joemarie-aliling.com/223/php-programming/php-memcache-not-found-problem/

http://joemarie-aliling.com/223/php-programming/php-memcache-not-found-problem/

回答by Bart McLeod

If you do not know which php.ini your command line is using, type php -i. You will get a long list of settings, where somewhere near the top of the list you will see which php.ini is being used:

如果您不知道命令行使用的是哪个 php.ini,请输入 php -i。您将获得一长串设置,在靠近列表顶部的某处,您将看到正在使用的 php.ini:

Configuration File (php.ini) Path => /Applications/MAMP/bin/php/php5.3.6/conf
Loaded Configuration File => /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)

回答by Richard Stelling

For simplicity sake I used:

为简单起见,我使用了:

php -c /etc/php.ini ./cli-script.php