简体   繁体   English

Memcache&php:致命错误:未找到类'Memcache'

[英]Memcache & php: Fatal error: Class 'Memcache' not found in

I have found several very similar issues. 我发现了几个非常相似的问题。 However, each points to using the wrong php.ini file or not have memcache installed at all, or having memcached and not memcache setup, etc, so I believe this issue is distinct despite the fact a search for that error turns up several discussions. 但是,每个人都指向使用错误的php.ini文件或者根本没有安装memcache,或者有memcached而不是memcache设置等,所以我相信这个问题是截然不同的,尽管搜索该错误会引发一些讨论。

Anyway, when I try to instantiate a new Memcache object, I get: 无论如何,当我尝试实例化一个新的Memcache对象时,我得到:

Fatal error: Class 'Memcache' not found in /websites/../app/app_controller.php on line 360 致命错误:第360行的/websites/../app/app_controller.php中找不到“Memcache”类

Because debugging stuff from the command line can sometimes give you bad info, I just added my debug to the pages: 因为从命令行调试东西有时会给你不好的信息,我只是将调试添加到页面:

<pre>
  <?= system('php -i | grep "php.ini"') ?>

  <?= system('php -i | grep memcache') ?>

  <?= system('php -i | grep extension_dir') ?>
</pre>

This gives me: 这给了我:

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

memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user sqlite memcache 
Registered save handlers => files user sqlite memcache

extension_dir => /usr/local/php53/modules => /usr/local/php53/modules

The memcache report tells me I have my php.ini file setup properly and the memcache.so file in the right place, but here is that info just to be clear: memcache报告告诉我我的php.ini文件设置正确,memcache.so文件在正确的位置,但这里的信息要清楚:

extension_dir = "/usr/local/php53/modules"
extension=memcache.so

and memcache.so is there: 和memcache.so在那里:

younker % la /usr/local/php53/modules/memcache.so 
-rwxr-xr-x  1 younker  staff  60196 Feb 14 10:56 /usr/local/php53/modules/memcache.so

So, I am obviously missing something, I just don't know why php can't find class Memcache. 所以,我显然缺少一些东西,我只是不知道为什么php找不到类Memcache。

This discussion has gone silent so I wanted to post my fix (which I just wrapped up). 这个讨论已经沉默,所以我想发布我的修复(我刚刚结束)。

Basically, I stopped using the apache/php combo that shipped with my os (mac osX 10.5.3) and re-installed. 基本上,我停止使用我的os(mac osX 10.5.3)附带的apache / php组合并重新安装。 I first tried homebrew but was getting a bunch of errors when trying to install wget and then again when trying to install justin hileman's php formula . 我第一次尝试自制软件,但在尝试安装wget时遇到了一堆错误,然后在尝试安装justin hileman的php公式时再次出现错误。 So having uninstalled macports as part of the homebrew troubleshooting process, I reinstalled macports and installed everything. 因此,作为自制程序故障排除过程的一部分卸载了macports,我重新安装了macport并安装了所有内容。 however, macports sucks and did not properly install php with mysql support, so I just grabbed the php binary I wanted and installed the old fashion way using the following config options: 然而,macports糟透了,并没有正确安装php与mysql支持,所以我只是抓住我想要的PHP二进制文件并使用以下配置选项安装旧时尚方式:

--prefix=/opt/local --with-mysql=/usr/local/mysql --enable-memcache --mandir=/opt/local/share/man --infodir=/opt/local/share/info --with-config-file-path=/opt/local/etc/php5 --with-config-file-scan-dir=/opt/local/var/db/php5 --disable-all --enable-bcmath --enable-ctype --enable-dom --enable-fileinfo --enable-filter --enable-hash --enable-json --enable-libxml --enable-pdo --enable-phar --enable-session --enable-simplexml --enable-tokenizer --enable-xml --enable-xmlreader --enable-xmlwriter --with-bz2=/opt/local --with-mhash=/opt/local --with-pcre-regex=/opt/local --with-readline=/opt/local --with-libxml-dir=/opt/local --with-zlib=/opt/local --disable-cgi --with-apxs2=/opt/local/apache2/bin/apxs --with-pear=/opt/local/lib/php --with-openssl=/opt/local

Everything is puppy dogs and rainbows at this point. 此时一切都是小狗和彩虹。

Oki so the memcache module is loaded , but what about the include path ? Oki所以加载了memcache模块,但是包含路径呢? the error tells you it can't find the memcache class so have a look at get_include_path and set_include_path functions and where the memcache class file is actualy located . 错误告诉你它找不到memcache类,所以看看get_include_path和set_include_path函数以及memcache类文件的实际位置。 From the looks i suppose you're app re-sets the include path but doesn't keep the default include path from php.ini when it should keep the old path aswell . 从外观上看,我认为你是应用程序重新设置包含路径但是不保留php.ini的默认包含路径,它应该保留旧路径。 smth like this : 像这样:

<?php
$path = '/some/app/include/path';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
?>

Use: 采用:

sudo a2enmod memcache

or similar. 或类似的。

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

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