开发者

Storing php function variables in memcached

I was wondering if it is possible to store function variables in memcached. I wrote basic templating system which compiles xml templates into functions. The templates can get very big and I think I could get a performance boost if I could cache it. Would something like this work, or would I just be caching a reference to the function?

$populate_template = function($values){
   //compiled template
};
$memcached_object->set("some_key",$populated_template);

EDIT: I do realize that there are php accelerators that do exactly what I 开发者_开发百科want, however it would be a lot easier to be able to use memcached because I won't have to go through the process of getting another technology approved.


I don't think so. Naturally, I looked at serializing it. But:

PHP Warning:  Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in php shell code:1

With memcached, all you can probably do is store the code as a string, then call create_function after you pull it out.


I don't think there would be a performance boost with "serializing" the function source code as a string and recreating it via create_function. It will rather be hundred times slower than defining the function in PHP, because of the input/output with external medium + doing what would PHP need to do in either case.

You need to go with an opcode cache. But if PHP performance is the only lasting bottleneck in your application, you're a happy man.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜