如何捕获致命错误:PHP超过30秒的最大执行时间 [英] How to catch the fatal error: Maximum execution time of 30 seconds exceeded in PHP

查看:91
本文介绍了如何捕获致命错误:PHP超过30秒的最大执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究自己正在开发的系统,并设法使它引起这个问题:

I've been playing around with a system I'm developing and managed to get it to cause this:

致命错误:最长执行时间超过30秒

Fatal error: Maximum execution time of 30 seconds exceeded

发生在我做一些不切实际的事情时,但是它仍然可能发生在用户身上.

It happened when I was doing something unrealistic, but nevertheless it could happen with a user.

有人知道是否有办法捕获此异常吗?我已经阅读了很多,但似乎每个人都建议增加允许的时间.

Does anyone know if there is a way to catch this exception? I've read around but everyone seems to suggest upping the time allowed.

推荐答案

您唯一的选择是增加脚本的允许执行时间(将其设置为0会使它无限执行,但不建议这样做)或生成新线程并希望是最好的.

Your only options are to increase the allowed execution time (setting it to 0 makes it infinite, but that is not recommended) of the script or spawn a new thread and hope for the best.

之所以无法捕获,是因为它并未真正抛出.没有一行代码实际触发该错误,PHP则说:不,对不起,这太长了.该关闭了."这是有道理的.想象一下,如果一个脚本的最大执行时间为30秒,那么在捕获一个错误的情况下又要花30秒钟的时间...在一个设计不良的程序中,这会带来一些相当可恶的利用机会.至少,它将为 DOS 攻击创造机会.

The reason that this isn't catchable is that it isn't really thrown. No one line of the code actually triggered the error, rather PHP said, "Nope, sorry, this is too long. Time to shut down now." And that makes sense. Imagine having a script with a max execution time of 30 seconds catching that error and taking another 30 seconds... in a poorly designed program, that opens up some rather nasty opportunities to exploit. At a minimum, it will create opportunities for DOS attacks.

这篇关于如何捕获致命错误:PHP超过30秒的最大执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆