1

By default Memcached module in PHP uses PHP's built in serialization functions. Because I'm accesing the same keys from other programming languages, I have found a serialization module that works in all languages. How do I use my serialization module instead of PHP's when storing/retrieving keys from Memcached?

2 Answers 2

4

If your memcached php module has been compiled with HAVE_JSON_API defined (which I think is true by default since php 5.2. Documentation says "Requires PHP 5.2.10+") you can set the JSON serializer with

$memchache->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_JSON);

(and there are json en-/decoders for many, many languages)

see http://docs.php.net/memcached.constants

Sign up to request clarification or add additional context in comments.

Comments

2

Just put your serialized data in a string and save it with memcache,

$memcache->add('your_key', str, false, 30);

If the serailization generates binary data. You should base64 encode it yourself because PHP's binary encoding is very in-efficient.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.