在memcached中存储php函数变量
我想知道是否可以在 memcached 中存储函数变量。我编写了基本的模板系统,它将 xml 模板编译成函数。模板可能会变得非常大,我认为如果我可以缓存它,我可以获得性能提升。像这样的东西会起作用,还是我只是缓存对该函数的引用?
$populate_template = function($values){
//compiled template
};
$memcached_object->set("some_key",$populated_template);
编辑:我确实意识到有 php 加速器 可以完全满足我的要求,但是它会是使用 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不这么认为。自然地,我考虑将其连载。但是:
使用 memcached,您所能做的就是将代码存储为字符串,然后在将其取出后调用
create_function
。I don't think so. Naturally, I looked at serializing it. But:
With memcached, all you can probably do is store the code as a string, then call
create_function
after you pull it out.我认为将函数源代码“序列化”为字符串并通过 create_function 重新创建它不会提高性能。它会比在 PHP 中定义函数慢一百倍,因为使用外部介质进行输入/输出 + 执行 PHP 在任何情况下都需要执行的操作。
您需要使用操作码缓存。但如果 PHP 性能是您的应用程序中唯一持久的瓶颈,那么您很高兴。
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.