10

I was trying to find any information about using Memcached with PHP7, but I failed. The only valuable information is short Readme.md of php-memcached repo.
Unfortunately, its travis build failed as well as 30/126 tests on my machine.

However make install command was successful and created memcached.so file. Does it mean I can use this extension in production or it still has bugs and is not recommended for using?

I will very appreciate any advice or working solution.

James Akwuh
  • 2,169
  • 1
  • 23
  • 25
  • I fixed the travis build ... if you have bugs, report them ... there's no possible way to guess ;) – Joe Watkins Apr 02 '16 at 19:49
  • @JoeWatkins will follow your advice in a short time, thank you – James Akwuh Apr 02 '16 at 19:53
  • Also, they are all experimental tests ... travis wasn't failing because of bugs in php-memcached, just bugs in the build script ... you should be fine. – Joe Watkins Apr 02 '16 at 20:03
  • @JoeWatkins thank for notice, that's important. Does it mean that current php-memcached#php7 is not covered with tests, so can not considered to be stable? – James Akwuh Apr 02 '16 at 20:34
  • No, the failures you have are in tests/experimental, which are not run by CI ... they cover experimental features ... – Joe Watkins Apr 03 '16 at 03:47
  • One important change in the php7 version of php-memcached is the removal of the $cas_token parameter from the get methods, I've written a post about this: http://developer.procurios.com/post/2016/05/17/Using-Memcached-with-PHP-7 – Taco May 17 '16 at 09:43

4 Answers4

11

You need to use the php7 branch; see here, Travis is passing.

This should be the complete set of steps to install the memcached extension on a Debian/Ubuntu OS:

sudo apt-get update
sudo apt-get install -y libmemcached-dev libmemcached11 git build-essential

git clone https://github.com/php-memcached-dev/php-memcached
cd php-memcached
git checkout php7
git pull

/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config

make
sudo make install

You may need to change some of the paths if you have them installed at different locations.

Will
  • 24,082
  • 14
  • 97
  • 108
  • 1
    I don't understand what I am meant to do with `/usr/local/php7/bin/phpize ./configure --with-php-config=/usr/local/php7/bin/php-config` `/usr/local/php7/bin/phpize` does not exist. – Jamie Hutber Jun 25 '17 at 12:14
  • @JamieHutber: "*If the system is missing the phpize command, and precompiled packages (like RPM's) are used, be sure to also install the appropriate devel version of the PHP package as they often include the phpize command along with the appropriate header files to build PHP and its extensions.*" -- http://php.net/manual/en/install.pecl.phpize.php – Oberst Jul 02 '17 at 13:41
  • @JamieHutber sudo apt-get install php7.0-dev and then /usr/bin/phpize is there – Hernán Eche Sep 24 '18 at 19:32
  • In my Ubuntu 18.04 setup with PHP7.2 I also had to `apt-get install pkg-config zlib1g-dev` and my `php`, `phpize` and `php-config` were in `/usr/bin`. – Chris Tophski Jun 17 '19 at 07:48
8

To install memcached on the latest ubuntu for the latest php use:

sudo apt-get install php-memcached
patrick
  • 11,519
  • 8
  • 71
  • 80
  • 1
    If a message error "No Memcached servers added" you need also to install: `sudo apt-get install memcached` and then it works! – dani24 Feb 28 '18 at 18:01
4

For Debian 8 users, you can use:

sudo apt-get install php7.0-memcached
  • Note that the extension version installed is this case is: **3.0.3**. Unfortunately I couldn't use it because it's considered as a new major version and not being supported by some old vendor libraries that check directly on the version number to initialize themselves. In this case the last version it supported was 2.2. – COil May 16 '17 at 08:52
0

I came to this question via an issue with getting artisan to work in the Laravel Lumen framework.

I'm using PHP 7. PHP 7.0.15-0ubuntu0.16.04.4 to be precise.

I found the only solution was to install what appears to be the PHP 5 version* with memcached:

sudo apt install memcached php-memcached


*

php-memcached/xenial,now 2.2.0-51-ge573a6e+2.2.0-2build2 amd64 [installed]
  memcached extension module for PHP5, uses libmemcached

If you find you then get the error: [RuntimeException] Could not establish Memcached connection., you need to install the memcached extension as the above sudo apt install memcached (if you're on 16.04+, use apt-get if < 16.04)

Jonathan
  • 10,936
  • 8
  • 64
  • 79