Sharing cache objects between PERL and PHP

josh rotenberg joshrotenberg at gmail.com
Fri Jun 22 21:25:06 UTC 2007


Your best (only?) option is to use some common format to
serialize/deserialize your session in both languages (JSON, XML, etc).
Perl and PHP both use a different method to serialize complex
structures.

On 6/22/07, The Newb <ne_wb at hotmail.com> wrote:
>
>
>  Hello,
>
>  I'm using Cache::Memcached on the PERL side and the PECL libraries for PHP
> in PHP 4.x. The data objects are session data that I would like to share
> between both languages, however when I telnet straight into the memcache
> daemon and do gets on the keys, it appears that the data objects are stored
> in completely different formats. Do I have a setting wrong, is this a
> permanent limitation, wrong library or not enough RTFM? It works fine in
> either language. I'm just missing the cross-compatability. If someone could
> point me toward correct answer, it would be much appreciated.
>
>  Thanks
>
>  ### PERL EXAMPLE
>
>  use Cache::Memcached;
> require Digest::MD5;
> my $memd = new Cache::Memcached {
>     'servers' => [ "127.0.0.1:11211"],
>  debug => 1
>   };
> $memd->enable_compress(0);
> $sess_id = "d116f2af6b07deaac588c8c34cca919b";
> $session->{'first'} = "john";
> $session->{'last'} = "smith";
> $session->{'session_id'} = $sess_id;
>
> $memd->set("$sess_id", $session,60);
>
>
>  ### MEMCACHE RESULT
>
>  telnet 127.0.0.1 11211
> Trying 127.0.0.1...
> Connected to localhost.localdomain (127.0.0.1).
> Escape character is '^]'.
> get d116f2af6b07deaac588c8c34cca919b
> VALUE d116f2af6b07deaac588c8c34cca919b 1 85
>   d116f2af6b07deaac588c8c34cca919b
> session_id
> johnfirst
> smithlast
> END
>
>  ### PHP EXAMPLE
>
>  $memcache = new Memcache;
> $memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
> $sess_id = "d116f2af6b07deaac588c8c34cca919b";
> $session->first = "john";
> $session->last  = "smith";
> $session->session_id  = "$sess_id";
> $memcache->set($sess_id,$session,false,900);
>
>  ### MEMCACHE RESULT
>
>  get d116f2af6b07deaac588c8c34cca919b
> VALUE d116f2af6b07deaac588c8c34cca919b 1 123
> O:8:"stdClass":3:{s:5:"first";s:4:"john";s:4:"last";s:5:"smith";s:10:"session_id";s:32:"d116f2af6b07deaac588c8c34cca919b";}
> END
>
> ________________________________
> Change is good. See what's different about Windows Live Hotmail. Check it
> out!


More information about the memcached mailing list