Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is PHP Memcached fully backwards compatible with Memcache?

Tags:

php

memcached

I am getting ready to upgrade a Debian server from PHP 5.6 to 7.0 via the dotdeb repositories. The Dotdeb repos do not have the (old) Memcache package, but they do have the (new) Memcached package. A third-party module I use relies on Memcache. Looking at the APIs, it appears that Memcached library should be fully backward compatible with Memcache, so that I can just do this:

if (!class_exists('Memcache') && class_exists('Memcached')) {
    class Memcache extends Memcached
    {
    }
}

In testing it seems to work. The comments on the memcached documentation mention at least one gotcha, but since I am not looking to run them both at the same time, this one is not a problem.

However, I can't find anything else that talks about compatability. Is this a safe way to ensure backwards compatability between Memcached and Memcache or do I need a more sophisiticated adapter?

like image 580
Matt Avatar asked Mar 13 '26 07:03

Matt


1 Answers

I'm not sure what has been going on with the PECL Memcache project, but the base Github project was updated to support PHP7, and yet remains unreleased in any official capacity (I need this as well so I've been keeping tabs on it).

A few weeks ago the Remi repo (CentOS/Fedora) published a PECL package based on these updates and it appears to be stable. If you are in need of this I would suggest you pull the Github repo and build the PECL extension. Without an official release it's the only thing I can suggest to you. This way you don't have to hack the older class to work with your existing code.

https://github.com/websupport-sk/pecl-memcache (unofficial)
https://github.com/php/pecl-caching-memcache (offical)

like image 62
Machavity Avatar answered Mar 15 '26 22:03

Machavity



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!