How to install memcached PHP extension on OSX

Homebrew removed homebrew-php since 31st March 2018 and you cannot longer install memcached extension from it.

You will have this error if you try to install it in the old way

brew install php56-memcached
Error: No available formula with the name "php56-memcached" 
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching for similarly named formulae...
==> Searching local taps...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.

To make it works on OSX, here is the new way to install it.
Make sure you have XCode installed.

brew install libmemcached
brew install pkg-config

For PHP < 7 run

pecl install memcached-2.2.0

For PHP > 7 run

pecl install memcached

Pecl will ask you the path of the library, you should answer "yes"

Everything should works as expected if you install your php version with

brew install php56 && brew link php56 --force

For PHP71 I had to do the following:

pecl download memcached
open memcached-3.0.4.tgz && cd memcached-3.0.4
phpize
./configure --with-zlib-dir=/usr/local/Cellar/zlib/1.2.11
make && make install