Sharing Memcache with PHP and Python


I am trying to share a Memcache key between Python and PHP. Python writes the key and PHP reads it. I am using the Cakephp framework, with php-pecl-memcache (not php-pecl-memcached), and the python-memcache all python library.


mc = memcache.Client( [""]) key = "key1" value = 1323779849 mc.set(key, value)


echo Cache::read('key1', 'memcached');

PHP can't read the variable, I get weird "MemcachePool::get() [http://php.net/memcachepool.get]: Failed to uncompress data" errors; I suspect it has to do with memcached flags that are set differently in each library.

This is what happens when I telnet to memcached:

Python sets key:

get key1 VALUE key1 1 12 1323779849 . END

PHP sets key:

get key1 VALUE key 1 0 12 1323779849 END <ul><li>Is there a way to override these flags and just 'do your own thing'?</li> <li>Are there php/python memcache libraries that play better together?</li> <li>Alternatively, is there a simple way to create a common memory space between python/php?</li> </ul>


Finally got it to work. Lot's of stuff wasn't working as expected.


One problem is that php and python use different flags to do different things. Not a problem in an all-python or all-php solution, but for inter-environment communication a real problem. A useful resource is <a href="http://www.hjp.at/zettel/m/memcached_flags.rxml" rel="nofollow">http://www.hjp.at/zettel/m/memcached_flags.rxml</a>, which shows that python-memcache flags long integer as '2', which php-memcache does not understand, hence the <em>compression error</em>. I amended python-memcache to include a 'flag-override' in the set function. This variable simply forces a particular flag irrespective of what python memcache thinks it ought to be. This allowed me to re-flag Int from 2 to 0. I will prob branch the current version of python-memcache and submit it to Github. This allowed me to force the python long int flag (2) to something php would understand (0).

</li> <li>

CakePhp prior to 1.3.3 stores all keys in memcached with an additional key_expires key, flagged as 768, etc, etc. Without this additional key it cannot find the key you are looking for. Thankfully this behaviour was dumped in later Cakephp version (I simply upgraded to 1.3.13) and it works well now.

</li> </ol>


When you put something via python memcached, it's probably pickled. So PHP cannot unpickle it. I would try to use some kind of very basic type maybe ctypes? Maybe raw strings?


  • SELECT UNCOMPRESS(text) FROM with sqlalchemy
  • Does an Android Device have to be rooted in order to telnet to it?
  • compress text before storing in mysql database
  • How to run a TCL script to tell run in every 10 minutes?
  • Linking libavcodec and libavformat: Undefined references
  • Acts as Tree with Multiple Models
  • Geo Fix not working in Android SDK 2.2
  • Objective-C – access extern const with a string containing its name? [duplicate]
  • How to grep for a specific pattern and print everything above and below that pattern until you reach
  • C# COM Component Fails To Read Config When Loaded Into An Unmanaged C++ App
  • How do I configure Maven Cargo to use an embedded Tomcat server?
  • Select column where another related column's total is 0
  • How to generate an asynchronous reset verilog always blocks with chisel
  • Cryptic error when trying to run POW
  • How to initialize context? [closed]
  • Passing parameter through “window.location.href”
  • Jenkins: could not create Android emulator failed to parse AVD config file
  • Unable to run tests with JUnit5 Console Launcher
  • Granting permissions to Azure Active Directory Web Application automatically
  • Slicing an SPA into several components and use AngularJS
  • Creating a C++ function that calls other Lua function
  • Let a function return any type in C++ class
  • react split panel resize
  • Android custom URI scheme incorrectly encoded when type in browser
  • Xaml, wpf image position and crop issue
  • Can you pass an array from javascript to asp.net mvc controller action without using a form?
  • Time out Error in send mail
  • In matplotlib, how do you change the fontsize of a single figure?
  • 550 Access denied - Invalid HELO name
  • pillow imaging ImportError
  • Entity Framework Code First TPC Inheritance Self-Referencing Child Class
  • Check for zero lines output from command over SSH
  • Problems installing Yesod for Haskell
  • Unable to install Git-core+svn by MacPorts
  • VSO Build — Response status code does not indicate success: 404 (Not Found)
  • ilmerge with a PFX file
  • JFileChooser in front of fullscreen Swing application
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • unknown Exception android
  • failed to connect to specific WiFi in android programmatically