Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class Memcache not found when executing in PHPUnit

I have installed the memcached and loaded the memcached extension, but when I was runnning a test with PHPUnit, it told class memcached not found. Can anyone tell me why, and how to solve it?

like image 875
hasayaki Avatar asked Sep 16 '26 02:09

hasayaki


1 Answers

For me the problem was I had two different php versions installed on my machine. One was with Memcached installed and the other was not. I just ran:

$ whereis php

And it listed the paths of the two php installations. Then I found which had the Memcached installed by executing:

$ /usr/bin/php -i | grep memcache
$ /usr/local/bin/php -i | grep memcache

If none of these return any matches, and you are sure you have Memcached installed, then you are using wrong php.ini as above comments suggested. You can try starting php with -c option, to specify the path to the php.ini:

$ /usr/bin/php -c /etc/php5/cli/php.ini

Then it was just a matter of using the correct php path when executing the unit tests:

$ /usr/bin/php vendor/bin/phpunit tests

Oh, and please note that there are two separate extensions - one is called "Memcache", and the other is "Memcached". If you installed one of it, and try to use the other, it won't work for obvious reasons.

like image 125
Shumoapp Avatar answered Sep 21 '26 12:09

Shumoapp