Php – Cannot load Memcached in PHP on Gentoo

gentoomemcachedPHP

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.

Best Answer

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

Related Topic