Solution for “Fatal error: Maximum function nesting level of '100' reached, aborting!” in PHP

后端 未结 22 2474
我寻月下人不归
我寻月下人不归 2020-11-22 16:45

I have made a function that finds all the URLs within an html file and repeats the same process for each html content linked to the discovered URLs. The function is recursiv

22条回答
  •  佛祖请我去吃肉
    2020-11-22 16:52

    Rather than going for a recursive function calls, work with a queue model to flatten the structure.

    $queue = array('http://example.com/first/url');
    while (count($queue)) {
        $url = array_shift($queue);
    
        $queue = array_merge($queue, find_urls($url));
    }
    
    function find_urls($url)
    {
        $urls = array();
    
        // Some logic filling the variable
    
        return $urls;
    }
    

    There are different ways to handle it. You can keep track of more information if you need some insight about the origin or paths traversed. There are also distributed queues that can work off a similar model.

提交回复
热议问题