"Memcache" not found in command line php script

I have Memcache installed and working for PHP applications running through Apache (v2.2), but when I try to run the .php file on 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:

 $memcache = new Memcache; 

Additional Information:

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

+15
command-line php apache memcached
Jul 23 '09 at 12:06
source share
5 answers

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

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

 extension=memcache.so 

On Ubuntu, it is in / etc / php 5 / cli / php.ini

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

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

+25
Jul 23 '09 at 12:14
source share

Perhaps you have a separate php.ini file for CLI mode. This file may not include the memcache extension.

+5
Jul 23 '09 at 12:13
source share

I had such a mistake and I also made php -i | grep memcache, and he says memcache is enabled, but my solution that resolved the problem was when I edited php.ini, I just changed the extension_dir = "./" line to the full path to the extensions directory, which now looked like this : extension_dir = "/ usr / local / lib" - you need to check where the php extension directory is located and make sure memcache.so exists.

then I just restarted httpd and, alas, the problem disappeared.

You can check the detailed steps here:

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

+2
25 Oct '09 at 6:45
source share

For simplicity, I used:

 php -c /etc/php.ini ./cli-script.php 
0
Jul 23 '09 at 12:28
source share

If you do not know which php.ini your command line is using, enter php -i. You will get a long list of settings, somewhere somewhere near the top of the list you will see which php.ini is 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) 
0
May 15 '12 at 7:34 a.m.
source share



All Articles