'Memcache' not found in command line PHP script
Asked Answered
L

5

16

I have Memcache installed and working for PHP apps run through Apache (v2.2) but when I try to run a .php file in the command-line i get this error:

Fatal error: Class 'Memcache' not found in /usr/local/Matters/app/matters-common/connection.php on line 94

Line 94 is:

$memcache = new Memcache;

Other info:

CentOS 5.2
PHP 5.2.5 (cli) (built: Feb 20 2008 21:13:12)
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
Apache v2.2.8

Leveller answered 23/7, 2009 at 12:6 Comment(0)
P
27

Presumably you have separate php.ini files set up for apache and the command line (cli).

If so, you need to add the following to your cli php.ini file:

extension=memcache.so

On Ubuntu it's in /etc/php5/cli/php.ini

If it's working then memcache should appear in the list of modules if you run php -m on the command line.

Alternatively, you can create a file /etc/php5/cond.d/memcache.ini with the same contents.

Plyler answered 23/7, 2009 at 12:14 Comment(1)
Are any other modules working for the cli? Is "extension_dir" set in the cli php.ini file? If memcache.so is in the default directory ( /usr/lib/php5/20060613/ for me) then you can leave extension_dir commented out.Plyler
D
5

It is possible that you have a separate php.ini file for CLI mode. This file might not include memcache extension.

Diastase answered 23/7, 2009 at 12:13 Comment(0)
P
2

I did have this kind of error and I also did php -i | grep memcache and it says memcache is enabled, but my solution that solved the problem was when I edited the php.ini, i simply modified the extension_dir="./" line to the full path of the extensions directory which now looked like this, extension_dir="/usr/local/lib" -- you need to check where the extension directory of the php reside and make sure memcache.so is there..

then i simply restarted httpd and alas the problem is gone.

you can check the detailed steps here:

http://joemarie-aliling.com/223/php-programming/php-memcache-not-found-problem/

Phylloxera answered 25/10, 2009 at 6:45 Comment(0)
L
0

For simplicity sake I used:

php -c /etc/php.ini ./cli-script.php
Leveller answered 23/7, 2009 at 12:28 Comment(1)
In a dev environment I tend to replace my cli php.ini with a symlink to the apache one so I only have one file (by default the only difference on Ubuntu is the memory limit is set to unlimited on the command line).Plyler
K
0

If you do not know which php.ini your command line is using, type php -i. You will get a long list of settings, where somewhere near the top of the list you will see which php.ini is being used:

Configuration File (php.ini) Path => /Applications/MAMP/bin/php/php5.3.6/conf
Loaded Configuration File => /Applications/MAMP/bin/php/php5.3.6/conf/php.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
Khalil answered 15/5, 2012 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.