PHP GD Allowed memory size exhausted

前端 未结 4 1996

I\'m trying to process a directory of JPEG images (roughly 600+, ranging from 50k to 500k) using PHP: GD to resize and save the images but I\'ve hit a bit of a snag quite ea

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 13:59

    In some cases you simply cannot anticipate the highest memory allocation that will be needed by the images you are about to process. To prevent a crash, you may include following commands before and after your loop :

    register_shutdown_function ('my_function');
    $mem_limit = ini_get ('memory_limit');
    ini_set ('display_errors', false);
    ini_set ('memory_limit', '400M');          // some high value
    

    (...your process...)

    ini_set ('memory_limit',$mem_limit);
    

    And place within the function "my_function ()" the code that will handle the crash.

提交回复
热议问题