views:

198

answers:

1

I am thinking of writing a PHP extension library that will use the memcached library. It is trivial to simply link my library to the memcache shlib.

However, I am not sure what will happen if my (extension library) user already uses memcache on his/her website. My questions are:

  1. Is it possible to have (possibly different versions) of memcache on the machine?
  2. Is it best to statically link or dynamically link to memcache when building the extension library? (to cater for version incompatibilities - assuming memcache is backward compatible, otherwise all bets are off)

The questions basically degenerate to how may one safeguard an extension library they have written if it has a dependence on a third party file which may already be being used on the website that the extension library is going to be used on?

The question may probably be slightly ill-posed, but I hope you understand the gist of what I am asking.

+3  A: 

Mind that there are two memcache extensions for PHP, one is called memcache, the other memcached, the first uses it's own implementation of the memcache protocol, the later uses the library.

If you're using the first you shouldn't have a conflcit but have to take care of memcache on your own. I'd suggest building an extension which depends on the memcached and re uses the library it found.

johannes
Useful info indeed Johannes. I'll read up on the two to get more info
Stick it to THE MAN
All the evidence is pointing to using memcached (which indeed you suggested as well). Now regarding implementation - can I directly make calls to the underlying C++ libmemcached library, or do I need to make my calls through the PHP extension for memcache? (I hope not the latter)
Stick it to THE MAN
If the extension is loaded the library is available and can be called. I'm a bit thinking aobut the compile step ... it is easy if ou build both extension as part of the PHP build (cd php-src/ext; cp -r $memcached/ .; cp -r $yourext; cd ..; ./buildconf; ./configure --with-memchached) .... building them individually might require you copy the library detection from memcached's config.m4 ... but I never looked into it, maybe you could ask for more opinions on pecl-dev [at] lists.php.net - the extesnsion's maintainer should read there, too
johannes
My quesstion is more to do with accesing memcache at runtime. I will dynamically link to libmemcache, so I can require that users of my lib have atleast version xxx of memcache installed and enabled for PHP. I wanted to know if I can directly call the C funcs from my library - (common sense suggests so - but you never know).Regarding your response though, I CANNOT possibly insist users install my "specially compiled" PHP, so I will have to assume that they are using the normal (i.e. baseline) PHP binary distro. Question is can I call libmemcache directly from my code?
Stick it to THE MAN
Yes you can. The thing I'm not sure about is a way to locate the headers while compiling the extension ...
johannes
Johannes - thanks for the clarification. I dont think compilation will be an issue - I'll download the source if required.
Stick it to THE MAN