douya2982 2012-04-02 09:07
浏览 161
已采纳

在PHP中出现内存耗尽错误后增加或清除内存

We currently have an error catching script for all our PHP sites. This script uses a combination of set_error_handler & register_shutdown_function to catch all errors that occur including Memory exhaustion errors then sends us an email so that we can respond and fix the error.

Unfortunately in case of memory exhaustion errors the script has no more memory and can't complete sending the email. I've tried updating the memory limit in the error handler function so the script can complete the error but this doesn't seem to work. Is there a way to force PHP to dump it's memory so that there is enough to send the error email? Or perhaps to detect and unset the largest memory items?

EDIT: I should clarify that I'm using PHPMailer to send an email. I'm looking into using just mail in the case of a memory exhaustion error.

  • 写回答

2条回答 默认 最新

  • duanlun4411 2012-04-03 11:00
    关注

    Looks like if I check for the exhaustion error and just use mail(), and don't create any variables, at the very top of the error_handler then PHP will send an email with no issue.

    I also have to be sure to preset anything that I wish to include in the email with the exception of anything passed to the error handler.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 ue5运行的通道视频都会有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数