views:

459

answers:

4

I am getting both modules listed as installed / configured when I use:

php -m

or if I use:

php -i

but when I use:

$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or 
$m = new Memcached;

I get the following error:

Fatal error: Class 'Memcached' not found

I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.

Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.

Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:

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

UPDATE:

Apache is failing to load the extension.

[Fri May 14 04:22:26 2010] [warn] Init: Session Cache is not configured [hint: SSLSessionCache] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so' - (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so' - (null) in Unknown on line 0

Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?

+2  A: 

because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout

Col. Shrapnel
This is my phpinfo output:Configuration File (php.ini) Path: /etcLoaded Configuration File: /private/etc/php.iniboth are the same.
Auston
+2  A: 

Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.

It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).

HTH

C.

symcbean
(or maybe you haven't restarted your webserver since changing the config?)
symcbean
It is failing to load the extension! Thanks!
Auston
+1  A: 

I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".

I would assume that the memcached.so file, or the directory it's in does not have proper permissions.

Mike Sherov
A: 

I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.

lucid311