Safely catch a 'Allowed memory size exhausted' error in PHP

后端 未结 4 1282
灰色年华
灰色年华 2020-11-27 13:45

I have a gateway script that returns JSON back to the client. In the script I use set_error_handler to catch errors and still have a formatted return.

It is subject

4条回答
  •  天命终不由人
    2020-11-27 14:06

    you could get the size of the memory already consumed by the process by using this function memory_get_peak_usage documentations are at http://www.php.net/manual/en/function.memory-get-peak-usage.php I think it would be easier if you could add a condition to redirect or stop the process before the memory limit is almost reached by the process. :)

提交回复
热议问题