PPTV hack version 2013 limit analysis of function nesting layer in unlimited PHP

Source: Internet
Author: User
function nesting, the name is a bit tangled, perhaps not very well understood. A more common special case of nested functions: Recursive functions, that is, functions nest themselves. Always thought that in PHP can not have too many function nesting, this is because in the past some time accidentally used recursion, when the depth of recursion reached 100, that is, the function nesting layer reached 100, the program will report a Fatal error. The following example:

Copy the Code code as follows:


function rt () {
static $i;
echo $i + +, '
';
RT ();
}
RT ();
Die ();


In my win7 + php5.3 environment, the error is as follows: Fatal error:maximum function nesting level of ' 100′reached, aborting!
Always think that PHP itself is limited, until one day to switch to the LIUNX environment in the command line mode to run, found that the program is limited to the dead loop. Different circumstances have different results, why? Well, we directly in the source code to find the error message, found that there is no relevant content, directly debug the entire implementation process, there is no error in the win. What's the reason? Switch to win again, find again, found in the Xdebug to see the error message. Start at line 1242 of the Xdebug.c file:

Copy the Code code as follows:


XG (level) + +;
if (XG (level) = = XG (max_nesting_level)) {
Php_error (e_error, "Maximum function nesting level of '%ld ' reached,
Aborting! ", XG (Max_nesting_level));
}


What does that mean? The previous function nesting layer limit is xdebug extension Plus, why this limit? In Xdebug, each function call is recorded in Xdebug, including nested function calls, memory in function calls, and time equivalents, which are used when analyzing program performance. Without this restriction, when the number of nested layers is too many, the machine will run out of memory. If this is a production environment server, then there will be some services are not available, of course, the production environment will not add this extension. However, there may be this extension on a multi-person shared development server, and if the machine is not available because of a developer's program error, so that all developers do not work, I think this may be the reason to add a limit.
What if we need to increase the number of layers in this limit? Change source, recompile xdebug extension? No, there is an item in the Xdebug configuration item called Xdebug.max_nesting_level, by default, in PHP.ini, this configuration item is commented, minus the comment, this value is the value you need, 200? Not enough, that 500, but this value is not too large, if recursion too much, on the performance of the program has a great impact, at this time, the form of a stack to implement recursion or replace recursion with the loop is a better solution, such as: Fibonacci sequence (Fibonacci) implementation, with the loop to achieve faster.
Conclusion: The function nesting of PHP itself is unlimited, if there is a limitation, it is also the limit of memory. This is because the function nesting of PHP is implemented in the form of a stack. For each function, a section of memory is allocated to store the contents of the function parts.

The above describes the PPTV cracked version 2013 unlimited PHP function nesting layer limit analysis, including PPTV cracked version 2013 Unlimited aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.