使 getimagesize() 引用缓存值

发布于 2024-11-03 02:09:32 字数 235 浏览 4 评论 0原文

我正在调整 zen-cart 网站以提高 CPU 效率。经过分析后,我发现 getimagesize 函数占据了页面加载时间的近 50%。图像存储在本地。一种选择是浏览 zen-cart 的源代码,并用自定义的函数替换该函数以引用缓存的值,因为图像很少更改。然而,由于 php 是开源的,也许还有另一个选择:有没有办法修改这个函数,使其只从缓存中读取一个值,每当我将图像上传到服务器时我都可以设置该值?也许可以通过向函数添加一个可选参数来使其从缓存中读取。

I am tweaking a zen-cart website to be more cpu efficient. After profiling it, I see that the getimagesize function is accounting for nearly 50% of page load time. The images are locally stored. One option is to go through zen-cart's source code and replace this function with something custom to reference a cached value since images are rarely ever changed. However, since php is open source, perhaps another option is available: Is there any way to modify this function to make it just read a value from a cache which I can set whenever I upload an image to the server? Maybe by adding an optional parameter to the function that makes it read from cache.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

小嗲 2024-11-10 02:09:32

有趣的想法,但这需要重新编译 PHP。虽然并非不可能,但从维护的角度来看这可能不是一个好主意:您必须在每次 PHP 更新时重新集成补丁。

但是,您也许能够重写getimagesize():似乎有 PHP 模块和库可以向 PHP 添加此功能。

我对其中任何一个都没有经验,但这里有一些关于如何执行此操作的建议:

Interesting idea, but this would require recompiling PHP. While not impossible, it's probably not a good idea from a maintenance point of view: You would have to re-integrate your patch on every PHP update.

However, you might be able to override getimagesize(): There seem to be PHP modules and libraries that can add this capability to PHP.

I have no experience with any of them, but here are some suggestions on how to do it:

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