如何减少图像 gd 中的内存使用量或加快进程以更快地释放内存
我有一个图像 GD 脚本,当前使用大约 9MB 内存。 我的流量很大,因此有时会耗尽我服务器上的大量内存。
有什么方法可以减少图像 gd 的内存使用吗? 或者至少使脚本处理速度更快,以便更快地取消分配正在使用的内存。
我尝试过改变图像质量,但没有效果。 我还尝试更改图像像素大小,它减少了内存使用量,但不多。
谢谢。
I have an image GD script which is currently using around 9MB of memory.
I get a lot of traffic and hence sometimes it using up hell lot of RAM on my server.
Is there any way to reduce memory usage for image gd?
Or at-least make script process faster so that it de-allocates the memory which it is using, faster.
I have tried changing image quality, it had no effect.
I also tried changing image pixel size, it reduced the memory usage, but not much.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不看代码就不可能判断,但除非它包含任何重大错误,否则答案可能是否定的。
您可以做的是使用外部
imagemagick
二进制文件 - 它在外部运行PHP 的脚本内存限制 - 但这是一种完全不同的技术,并且需要您重写代码。我假设你已经缓存了 GD 的结果,所以不是每个请求都会导致它运行?
It's impossible to tell without seeing the code, but unless it contains any major mistakes, then the answer is probably no.
What you might be able to do is use the external
imagemagick
binary instead - it runs outside PHP's script memory limit - but that is an entirely different technology, and would require you to rewrite your code.I assume you are already caching GD's results so not every request causes it to run?
如果您担心内存限制,请尝试避免即时使用图像 GD。
不看代码很难解决问题,但我可以提出建议。
使用不同的进程来处理图像,例如,如果要调整图像大小,请不要在每次用户访问页面时都调整它们的大小,而是运行 cron 或带有窗口的调度程序来调整所有需要定期调整大小的图像的大小并拯救他们。所以开销会更少。
如果您提供更多代码,您将获得更好的帮助
Try avoiding using image GD on the fly if you are concerned about memory limits.
It's hard to solve the problem without seeing code, but i can make a suggestion.
Have a different process handle the images, for example, if you want to resize images, don't resize them everytime the user access a page, instead run a cron or a scheduler with window to resize all the images that needs to be resized periodically and save them. so there will be less overhead.
If you provide more code you will get better help