使 getimagesize() 引用缓存值
我正在调整 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的想法,但这需要重新编译 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: