3
votes

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?

2
developpaper.com/… This article shows with example too. Memcached is not compatiable with memcachetom10271

2 Answers

1
votes

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)

0
votes

To answer my own question, no the two are not compatible. For anybody who may run into this issue, I wrote a small shim that replicates parts of the Memcache API and passes it through to Memcached. It is available for download on SourceForge.