在memcached中存储php函数变量

发布于 2024-11-16 00:25:43 字数 439 浏览 2 评论 0原文

我想知道是否可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生生漫 2024-11-23 00:25:43

我不这么认为。自然地,我考虑将其连载。但是:

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

使用 memcached,您所能做的就是将代码存储为字符串,然后在将其取出后调用 create_function

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.

霞映澄塘 2024-11-23 00:25:43

我认为将函数源代码“序列化”为字符串并通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文