Mac PHP Fatal error: Class ‘Memcache’ not found

I’ve had this weird problem developing PHP Memcache these days. The Memcache environment was installed successfully but the running code always reported an error

$mem = new Memcache();
echo $mem->get("foo");

Running tips PHP Fatal error: Class ‘Memcache’ not found in/Users/XXXXXXXXX/demo/index. The PHP on line 9
Finally, using baidu, Google and their own various experiments finally found the cause of the problem:
code did not find the corresponding file

1, install memcache

brew search memcache

Find memcache (note: not memcached) that corresponds to the PHP version installed on your computer.
is installed using brew

brew install php56-memcache

When the installation is complete, the php56-memcache installation directory will be viewed

2, configure php.ini
add at the end of php.ini

extension_dir = /usr/local/Cellar/php56-memcache/2.2.7
extension =

Finally, rerun it, and you’ll see the magic: it worked

Read More: