IRC Php 机器人 - 嵌套错误
我使用的是 SimplePhp IRC BOT,你可以看到所有代码就在页面上。
我遇到的问题是主函数递归地调用它,因此在 100 次调用之后,它只是出错并出现以下错误:
致命错误:达到“100”的最大函数嵌套级别,正在中止!在 C:\xampp\xampp\htdocs\league\bot.php 的第 106 行 中,
我将粘贴下面的一些主要函数:
function main($config)
{
$data = fgets($this->socket, 256);
echo nl2br($data);
flush();
$this->ex = explode(' ', $data);
if($this->ex[0] == 'PING')
{
$this->send_data('PONG', $this->ex[1]); //Plays ping-pong with the server to stay connected.
}
$this->main($config);
}
有没有办法在函数不递归调用自身的情况下实现相同的功能?有这种级别的嵌套可以吗?我应该增加嵌套限制 xdebug 吗?
I'm using SimplePhp IRC BOT, you can see all the code right on the page.
The problem I'm running into is the main function calls it recursively, so after 100 calls, it just errors out and I get this error:
Fatal error: Maximum function nesting level of '100' reached, aborting! in C:\xampp\xampp\htdocs\league\bot.php on line 106
I'll paste some of the main function below:
function main($config)
{
$data = fgets($this->socket, 256);
echo nl2br($data);
flush();
$this->ex = explode(' ', $data);
if($this->ex[0] == 'PING')
{
$this->send_data('PONG', $this->ex[1]); //Plays ping-pong with the server to stay connected.
}
$this->main($config);
}
Is there a way to achieve the same functionality without the function calling itself recursively? Is it alright to have this level of nesting and should I just increase the nesting limit xdebug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的——一个 while() 循环。
这种类型的无限递归在 PHP 中不会有效地工作,因为它不会消除尾部调用。虽然您可以增加嵌套限制,但最终会消耗越来越多的内存,然后最终崩溃。
Yes — a
while()
loop.Unlimited recursion of this variety will not work effectively in PHP, as it doesn't eliminate tail calls. While you can increase the nesting limit, you'll just end up burning more and more memory before eventually crashing.