开发者

how to reduce memory usage in image gd or speed up the process to deallocate memory faster

开发者 https://www.devze.com 2023-03-07 22:32 出处:网络
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.

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 re开发者_StackOverflow中文版duced the memory usage, but not much.

Thanks.


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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号