Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memcache & php: Fatal error: Class 'Memcache' not found in

Tags:

php

cakephp

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.

like image 836
ynkr Avatar asked Jan 21 '23 12:01

ynkr


2 Answers

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.

like image 104
ynkr Avatar answered Jan 23 '23 02:01

ynkr


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);
?>
like image 23
Poelinca Dorin Avatar answered Jan 23 '23 00:01

Poelinca Dorin