PHP7 and Memcache: php-memcache versus php-memcached [EN]

Memcache and PHP7, did you struggle? So did I…

When I had to move some application to newer server hardware, I experienced crashes of the application. In the servers log there were remarks of it looking like this.

[Fri Jan 27 10:56:48.863150 2017] [core:notice] [pid 29007] AH00052: child pid 7363 exit signal Aborted (6)
*** buffer overflow detected ***: /usr/sbin/apache2 terminated
======= Backtrace: =========
======= Memory map: ========
562806e9e000-562806f35000 r-xp 00000000 09:02 59251002 /usr/sbin/apache2

I was googling for several hours, but found no real reason. So I checked to log above, and went into the source of my PHP application, and was narrowing the possible triggers of this strange behavior. I found the php-memcache module guilty, because when the crash appears it was in use, and some lines from the log where mentioning memcache as well. However, I’m using memcache quite heavily, and not all pages I was using it were crashing. Just those with many hits to the memcached were not working properly. Memcache itself was up and runnning, no sign for blaming the daemon. Now I was focussing on php memcache vs. php-memcached. By changing my code to use the php memcached the errors went away completely.

There are quite some posts out there mentioning incompatibilities between php7 and php-memcache. And it seems those posters are right.

My former source looked roughly like this:

$memcache = new Memcache;
$memcache->connect("localhost", 11211);
$somestuff = $memcache->get("someobjects"); something
$memcache->set("someobjects", $somestuff, 0, 60);

The change for the lazy ones was..

$memcache = new Memcached;
$somestuff = $memcache->get("someobjects"); something
$memcache->set("someobjects", $somestuff, 0, 60);

Ready to go…in fact, only the bold lines faced changes.

Btw, the server installation was a fresh Ubuntu 16.04 LTS with Apache 2.4.18 and PHP 7.0.13. In case the php-memcached module is not installed, simply apt install pgp-memcached && service apache2 restart will do…

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

PS PHPCaptcha WP
PS PHPCaptcha for Wordpress