How to recover from a fatal error “Allowed memory size exhausted”

前端 未结 7 900
梦如初夏
梦如初夏 2021-01-04 08:52

Do you know any solution to recover from the PHP fatal error : \"Allowed memory size ... exhausted\"

I have a shutdown function that is called when a fatal

7条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 09:25

    One I can think of is that you when you're doing your memory intensive operation you manually query memory_get_usage() on a regular basis (e.g. every loop iteration) and dump out your headers/error when it goes over some failsafe value which is below the script limit. It will slow your script down a lot, but at least you'll get something back.

    Or, and you may not be able to do this, run the memory intensive stuff as a CLI-based script called from inside your web-based stuff by using exec. The CLI part might fall over, but the web part will be able to report on it.

提交回复
热议问题