Memcached PHP Sessions

Reinis Rozitis roze at roze.lv
Fri Feb 2 22:27:44 UTC 2007


> What I suggested was an extra wrapper, in PHP case maybe function that
> would you call instead of original set function. That function would
> give you a notion that you are setting (or getting) an array,
> where you would actually be setting (or getting) a normal memcached
> object.
>
> I mean something like this:
>
> You call your_func_set(variable[x]) which in turn saves your
> index like var_x or varx....
>
> Now, when you want to get a specific index, you call something like
> your_func_get(var[x]) which in turn calls get(var_x).

It becomes a bit tricky there in your case..

Lets say you make such wrapper (its fully possible code-wise to alter 
set/get functionality (there is the open source pecl extension and also 
using sockets http://code.sixapart.com/svn/memcached/trunk/api/php/ )). You 
cant really fetch from memcached 'var' expecting it to be the whole array 
unleast your_func_get() does know all of the array indexes (and does 
multiple/batch fetching) there is no way Memcached can return anything :)

If you really like to operate with arrays pass the keys as array:
$var = memcached_get(array('x','key1','key2','key3')); will make you an 
associative array where you will have $var['x'] => 'some val'  $var['key1'] 
=> ...

That's why at this point storing php arrays in some custom way I see a bit 
useless.
In my opinion the thumb up rule is to store and fetch data in smaller 
chunks - you always know what key/object you should get. And in case you 
need to fetch/change only one element of an array the overhead getting the 
whole data and puting it back wont be that serious.


rr 




More information about the memcached mailing list