Storing complex data structures in PHP's Shared Memory

234 views Asked by At

I've got some complex data structure (objects and stuff) shared among all of my PHP scripts and right now I'm storing that serialized in session. It could boost my server's performance if I didn't have to serialize and unserialize it for each incoming request. This data structure holds application's ACL information so it is the same for all of the application's users, so it's a perfect candidate to be shared among all requests (regardless of which user the request came from).

I googled for PHP Shared Memory and these functions came up. They are perfect, it's just that they can only hold strings. They are of little use to me if I can't store my data structure as is. I mean if I have to serialize and unserialize my data structure for each request, that's not that much of help.

Does anyone have any shared memory solution for me where I can store my data AS IS?

1

There are 1 answers

0
Andy Nghi On
  1. Store your complex object into memcached.

  2. Refactor your complex data structure into 2 parts: one is frequently use (on all requests), one is rarely use. You can store data redundant (one value can stayed in both frequently and rarely used parts) so that the complex part is rarely be used.

  3. If every request need access the whole complex object. You need to build an algorithm to extract the data you need instead of unserialize it as object and use.