4
votes

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.

Anyway, when I try to instantiate a new Memcache object, I get:

Fatal error: Class 'Memcache' not found in /websites/../app/app_controller.php on line 360

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:

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

and memcache.so is there:

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.

3
Since you didn't mention it, have you restarted your webserver after installing/enabling memcache?netcoder
RE: Possible Duplicate? I have looked at that post and the issue there was that they had two different php.ini files. One was read from the cmd line and the other for the website. I have verified that my php.ini file is the proper one; that is also why I used the commands I would use on the cmd line directly in the cakephp app thus ensuring I was seeing the right config info. So, I don't think this is a dup of that ticket. RE: Restart? Yes, I restart the server whenever a change is madeynkr
RE: rights at directory Which directory specifically are you asking about? My /usr/local/php53/modules dir is 755 as is the memcache.so file. If there is another file/dir you are referring to, please let me know.ynkr

3 Answers

4
votes

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. 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. So having uninstalled macports as part of the homebrew troubleshooting process, I reinstalled macports and installed everything. 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:

--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.

3
votes

Oki so the memcache module is loaded , but what about the include path ? 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 . 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 . smth like this :

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

Use:

sudo a2enmod memcache

or similar.