PHP Imagick memory leak

后端 未结 4 703
庸人自扰
庸人自扰 2020-12-09 20:34

I have to render something with Imagick on PHP CLI. I have noticed that every 3-5 days the server memory gets full, so i can\'t even connet via ssh or ftp.

with memo

4条回答
  •  一生所求
    2020-12-09 21:06

    You can use this.

    Note that clear() is preferred over destroy() according to the docs to release memory use.

    // clear temp files
    $imagick_image->clear(); // in your case "$img->clear();"
    

    You can also run a cron to delete the temp files for you, otherwise your server could crash. This is not php code, it is command line code.

    # linux command
    find /tmp/ -name "magick-*" -type f -delete
    
    # cron
    45 * * * * find /tmp/ -name "magick-*" -type f -delete
    

提交回复
热议问题