0

I am using Gentoo Base System release 2.0.3, apache-2.2.21-r1, php 5.3.8-pl0 and memcached-1.4.5. I have done the following:

emerge dev-php/pecl-memcache emerge dev-php/pecl-memcached emerge dev-libs/libmemcache emerge dev-libs/libmemcached 

all install just fine. I have started memcached and can telnet on the port and run stats command. Of course, I didn't forget to restart apache.

Now, for the PHP part:

ls -lh /etc/php/apache2-php5.3/ext-active/ lrwxrwxrwx 1 root root 41 Jan 6 09:58 memcached.ini -> /etc/php/apache2-php5.3/ext/memcached.ini lrwxrwxrwx 1 root root 40 Jan 6 09:48 memcache.ini -> /etc/php/apache2-php5.3/ext/memcache.ini 

both containing extension=memcache.so and extension=memcached.so respectively.

php -i|grep memcache Additional .ini files parsed => /etc/php/cli-php5.3/ext-active/memcache.ini, /etc/php/cli-php5.3/ext-active/memcached.ini memcache memcache support => enabled memcache.allow_failover => 1 => 1 memcache.chunk_size => 32768 => 32768 memcache.compress_threshold => 20000 => 20000 memcache.default_port => 11211 => 11211 memcache.hash_function => crc32 => crc32 memcache.hash_strategy => consistent => consistent memcache.lock_timeout => 15 => 15 memcache.max_failover_attempts => 20 => 20 memcache.protocol => ascii => ascii memcache.redundancy => 1 => 1 memcache.session_redundancy => 2 => 2 memcached memcached support => enabled libmemcached version => 0.39 Registered save handlers => files user memcache memcached php -m | grep -i memcache memcache memcached 

So everything is pointing to the fact that memcache and memcached modules are loaded in PHP, BUT if I use a <?php phpinfo() ?> it doesn't display any as loaded modules, it only shows:
Additional .ini files parsed /etc/php/apache2-php5.3/ext-active/memcache.ini, /etc/php/apache2-php5.3/ext-active/memcached.ini
session.save_handler memcache memcache
session.save_path tcp://localhost:11211 tcp://localhost:11211
the two values mean Local Value and Master Value. Also, if I run a test code for memcached, like the following:

<?php $memcache = new Memcache; $memcache->connect('localhost', 11211) or die ("Connexion impossible"); $version = $memcache->getVersion(); echo 'Version: '.$version; $memcache->set('key', 'koreus', false, 10) or die ("Echec de la sauvegarde des donné sur le serveur"); echo "Les donné ont é stocké dans le cache (les donné expireront dans 10 secondes)"; $get_result = $memcache->get('key'); echo 'Donné depuis le cache : '. $get_result; ?> 

I get the following error message: Fatal error: Class 'Memcache' not found in /var/www/test/mem.php on line 2

Any ideas on this? I am new to Gentoo and didn't find anything special related to configuring memcached+php on it.
Thanks.

2
  • Silly question, but did you restart your Apache instance after installing the module? Commented Jan 6, 2012 at 9:58
  • yes, I did restart it. Commented Jan 6, 2012 at 10:01

2 Answers 2

2

Your current situation is that memcache and memcached are correctly loaded on the command line from /etc/php/cli-php5.3/ext-active/ but are not loaded by Apache from /etc/php/apache2-php5.3/ext-active/.

Assuming that the CLI versions of these files are exactly the same as the Apache versions, it might be worth checking /etc/php/apache2-php5.3/php.ini to make sure it is correctly including the files in the extensions directory.

Run diffs on everything under /etc/php/cli-php5.3/ and /etc/php/apache2-php5.3/.

1
  • Thank you so very much. I had extension_dir = "/etc/php/apache2-php5.3/" activated in /etc/php/apache2-php5.3/php.ini. I disabled it and it's working. Thanks for healing 2 days worth of pain. Commented Jan 6, 2012 at 12:13
0

The classic "memcache vs. memcached"... :-) These posts can help:

PHP memcached Fatal error: Class 'Memcache' not found: https://stackoverflow.com/questions/2659035/php-memcached-fatal-error-class-memcache-not-found
memcache vs memcached?

3
  • Yes, I have encountered this already as I did search my error prior to posting here. That is why I have installed both Memcache and Memcached. Also, Memcached php module is not to be confused with memcached -> the daemon. Commented Jan 6, 2012 at 10:12
  • But have you tried uninstalling "memcached" from PHP (the module, not the daemon)? Commented Jan 6, 2012 at 10:15
  • why should I do that? Anyway, first I tried just with one module installed and it also didn't work, then I installed both. But fine, I will give it a try again. Commented Jan 6, 2012 at 10:21

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.