0

When i set nesting level more than 415 it gives error page is not working and set it by 400 then give error Maximum function nesting level of '415' reached, aborting!

function actionIndex(){
    $limit = 1000;
    ini_set('xdebug.max_nesting_level', $limit);
    $queryTopics = "SELECT tr.id,tr.`parent_id`, tr.`child_id`, tr.`order_by`, tr.`level`, tr.`child_id` AS `tid`, t.`name`,t.`seo_name`
                    FROM `topic_relations` tr
                    LEFT JOIN `topics` t ON tr.`child_id` = t.`id`
                    WHERE t.`status` = 1";
    $topicss = \Yii::$app->db->createCommand($queryTopics)->queryAll();
    $topics = array();
    foreach ($topicss as $key => $value) {
        $parentIdCombination = $this->findAllParent($value['id']);
        $combination = array_reverse($parentIdCombination);
        $combinations = implode($combination, ' ');
        $topics['parent_combination'] = $combinations;
        unset($combination);
        $topics[] = $value;
    }
    $data['topicsParentChildArr'] = $this->buildTopicsTree($topics);
    echo '<pre>';
    print_r($topics);
    return $this->render('index',['data'=>$data]);
}

this function call recursively

function findAllParent($id) {
    global $combination;
    $parentTopicQuery =  "SELECT * FROM `topic_relations` where id=".$id;
    $topic_row = \Yii::$app->db->createCommand($parentTopicQuery)->queryOne();

    if($topic_row['level']>0) {
        $combination[] = $topic_row['child_id'];
        $parentTopicQuery1 =  "SELECT * FROM `topic_relations` where child_id=".$topic_row['parent_id'];
        $topic_row1 = \Yii::$app->db->createCommand($parentTopicQuery)->queryOne();
        $this->findAllParent($topic_row1['id']);
    }else {
        $combination[] = $topic_row['child_id'];
    }
    //var_dump($combination);
    return $combination;
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
nageen nayak
  • 1,262
  • 2
  • 18
  • 28
  • What is your question? And if this a production site, why are you running xdebug in it? – Gordon Jun 21 '18 at 08:46
  • How can increase the maximum nesting loop level?? – nageen nayak Jun 21 '18 at 08:49
  • you need to change it on php.ini its called `xdebug.max_nesting_level` https://stackoverflow.com/questions/4293775/increasing-nesting-function-calls-limit – Inus Saha Jun 21 '18 at 08:50
  • i did but its not working for me. – nageen nayak Jun 21 '18 at 08:53
  • @InusSaha [`xdebug.max_nesting_level` is `PHP_INI_ALL`](https://github.com/xdebug/xdebug/blob/master/xdebug.c#L349) so setting it via `ini_set` like the OP did should work – Gordon Jun 21 '18 at 08:56
  • Asking again: do you need xdebug for something? if you dont need it, uninstall the extension and the error will be gone and your site about 400% faster. – Gordon Jun 21 '18 at 08:58
  • 2
    I think this is a case of a typo: the innermost query is actually executing the outer query, not the inner one. The inner one should read `createCommand($parentTopicQuery1)` instead of `createCommand($parentTopicQuery)` (note the "1"). Because of this, the code will recurse for ever until an error occurs. I vote to close as typo. – trincot Jun 21 '18 at 09:11
  • If it's looping 415 times, this is more likely a recursive error. Increasing the limit isn't a solution more a hope that it works for now. – Nigel Ren Jun 21 '18 at 09:12
  • so was it a typo error as mentioned by trincot ? or that was because it was typed in here? although he sounds logical – Muhammad Omer Aslam Jun 22 '18 at 00:27

1 Answers1

1

There's no such limitaiton in PHP. The max function nesting level is a limitation of the xdebug extension.

If you want/need to increase this, just change the php.ini setting xdebug.max_nesting_level. I.e. you could use 2000.

xdebug.max_nesting_level = 2000

I have to mention, that this only applies for your development server. On production environments, there should never be the xdebug extension installed.

Philipp
  • 15,377
  • 4
  • 35
  • 52