views:

167

answers:

3

I am writing an application and I will have some dictionary values in many different languages. I know I could use GetText, but AFAIR files have to be compiled after editing, and I want to let user edit dictionary, and I can't recompile .mo files on the server. I don't know how many languages will be used, so solution must be elastic.

I designed database so it works good, and schema looks fine, but for every dictionary value there are a couple of joins, so the solution is not too fast.

For that reason I am thinking of storing dictionary values once, and refresh it only after editing a value in it. Unfortunately, PHP static variables couldn't be used, because they die at the end of the request. I don't want to use session, because I will have to make DB calls per user. Ideally I would like to use static variables just as in Java - they are living as long as application live in JVM.

What is the best solution to store some variables (in my example - dictionaries, dictionary entries, etc.) for a long time (not per request) for all users (not per user)?

I am thinking of making something like DictionaryValues class, serialize it once, and then deserialize it every request. Every time somebody will edit dictionary, object will be serialized again and will replace old serialized object. Of course editing will occur rarely compared to how often dictionary values will be read.

Is this a good solution? Should I serialize the object and store it on the disk or write it to the database? Which one is faster?

Maybe you find better solution for that problem?

+4  A: 

You could try PHP APC. It is fast and easy to use. You can serialize/deserialize objects and store/get them easily.

In a distributed environment, you could perform the same functions using memcache.

jldupont
+1  A: 

There are a couple of options:

  1. You could use shared memory (shmop or memcache).
  2. You could cache to a file or database - try PEAR::Cache_Lite (or APC as @jldupont suggests)
Greg
+2  A: 

A few options if memcache / APC is too much or not possible:

You could "compile" your database values frequently into a PHP file and include that. That would be the fastest parsing- and processing-wise.

If you don't need every dictionary value in each page (very likely, isn't it?) you might want to use a caching table that can work without the JOINs. That would be the best solution from a footprint perspective.

Pekka