php超过在递归中抛出异常的执行时间 [英] php exceeds execution time on throwing an exception in recursion

查看:474
本文介绍了php超过在递归中抛出异常的执行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:从头开始重写,旧问题无效



在递归中抛出异常后,我发生错误。
异常没有被抓到任何地方,它应该弹出并显示未捕获的异常错误,它没有。相反,它会产生时间限制命中类型的错误。如果我将var_dumps放在我的代码中,它看起来像抛出异常,但是它超过限制后才冻结并失败。



这是递归函数的一部分:

  if($ this-> prvky [$ iA]  - > ini< 1 || $ this-> ; prvky [$ iB]  - > ini< 1){
echo'--- THROWING ---';
throw new \OutOfBoundsException('ini小于1');
}

它在测试中运行得很好,异常可以抛出,如果是,它在未捕获的异常成功失败。



当没有异常抛出时,它在现实世界中运行良好。



但是当现实世界中的条件通过并抛出异常时, --- THROWING --- 其后应该是未捕获的例外,而是自动关闭疯狂,并在一段时间后失败,生成超时限制错误。我知道这个例外是被抛出的,我知道肯定我没有在任何地方捕捉异常。

解决方案

真正的问题是组合的内存不足错误,可悲的是没有显示,xdebug中的疯狂设置和对象连接产生大量数据。 / p>

由于这种疯狂的设置,异常会保存所有传递给函数的值,因此发生内存不足:

  xdebug.var_display_max_depth = -1 
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1

很久以前我放在我的xdebug中,忘记了。
那些引用其他对象的对象等等,整个结构(很多长配置)在每个调用上反复存储在堆栈中。我虽然应该只用xdebug来处理,但是似乎一旦抛出异常,xdebug将这个信息添加到异常的堆栈副本中,从而消耗大量的内存。 (可能只是我的解释)



但是打印不合时宜而不是的记忆。根据日志, 错误(同一请求中的2个致命错误)一个接一个地发生,但只打印了第二个错误。来自堆栈的数据真的很长,所以在内存限制被击中之后很久,当尝试将堆栈写入日志时,它超出了时间,产生了第二个错误,而不是第一个错误。


Edit: rewrote from scratch, the old question wasn't useful

I've got an error occuring after throwing an exception inside recursion. The exception is not caught anywhere, it should just pop up and show uncaught exception error, which it doesn't. Instead, it produces time limit hit kind of error. If I put var_dumps in my code, it looks like the exception is thrown, but then it just freezes and fails after it exceeds limit.

this is part of the recursive function:

if($this->prvky[$iA]->ini < 1 || $this->prvky[$iB]->ini < 1){
    echo '--- THROWING ---';
    throw new \OutOfBoundsException('ini is smaller than 1');
}

It runs very fine in tests, exception can be thrown and if it is, it successfully fails on uncaught exception.

In runs fine in real world when no exception is thrown.

But when condition passes in real world and exception is thrown, --- THROWING --- gets printed, which should be followed by uncaught exception, but instead it spins off crazy and fails after a while, producing time limit exceeded error. I know for sure that the exception is thrown and I know for sure that I'm not catching the exception anywhere.

解决方案

The real problem was combination of out of memory error that sadly didn't show up, insane settings in xdebug and object connectedness producing lot of data.

Out of memory happened because the exception kept track of all values passed to functions, thanks to this insane settings:

xdebug.var_display_max_depth = -1
xdebug.var_display_max_children = -1
xdebug.var_display_max_data = -1

which I put in my xdebug long time ago and forgot about. So those objects that have references to other objects and so on, the whole structure (lots of long configs) got stored in the stack repeatedly on each call. I though this should be handled only by xdebug, but it seems like once an exception is thrown, xdebug adds this info to exception's copy of stack thus consuming lot of memory. (probably, just my explanation)

But it printed out of time instead of out of memory. According to logs, both errors (2 fatal errors in the same request) happened one after the other, but only the second one was printed. The data from stack was really long, so it exceeded time when trying to write the stack in logs, long after the memory limit was hit, producing second error, that got printed instead of the first one.

这篇关于php超过在递归中抛出异常的执行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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