Results 1 to 8 of 8

Thread: CakePHP relationships suddenly started causing "Maximum function nesting level ..."

Hybrid View

  1. #1
    Join Date
    Aug 2007

    Question CakePHP relationships suddenly started causing "Maximum function nesting level ..."

    Hi all,

    I've been making some changes to a project I'm developing and I have a model as follows:
    PHP Code:
     * The projectlink model represents the link Project HABTM Project.
     * Because of the complexity of this relationship there are two relationships: Project HABTM Parent(Project) and Project HABTM Child(Project).

    class ProjectLink extends AppModel {
    $name "ProjectLink";
    $actsAs = array("Containable");
    $belongsTo = array(
    "Parent"    =>    array(
    "className"        =>    "Project",
    "foreignKey"    =>    "from_project_id"
    "Child"        =>    array(
    "className"        =>    "Project",
    "foreignKey"    =>    "to_project_id"

    It's been working for at least a few months but now when I go to any of the actions relating to this model I get the following from xdebug:

    Fatal error: Maximum function nesting level of '100' reached, aborting! in /Users/gid/Sites/primary-energy-research/cake/libs/debugger.php on line 248
    The following function cycle is getting repeated over and over again (and the cycles are nested inside each other):
    1. ClassRegistry->init( )
    2. Model->__construct( )
    3. Model->__createLinks( )
    4. Model->__constructLinkedModel( )

    So it looks like the relationships are going round in a spiral until it hits:
    1. ClassRegistry->init( )
    2. ClassRegistry->__duplicate( )
    3. ClassRegistry->isKeySet( )
    4. Debugger->handleError( )

    Unfortunately after that it's got to 100 nested functions so it bails.

    Any ideas guys?

  2. #2
    Join Date
    Aug 2004
    Is this modeling some sort of hierarchical data, with perhaps the problem being that the number of hierarchical levels in your database has increased over time until this error arises?
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Nov 2008
    Is it possible you actually are instantiating objects spanning that many levels of relationship? In other words, has your nesting got so large over time that you are trying to load a model, which loads its child, which loads its child and so on? If this is the case you could look into lazy-loading your objects.

    Another thought - have you recently upgraded to PHP5.3? If so does setting debug: 0 get rid of the issue?
    The first rule of Tautology Club is the first rule of Tautology Club.

  4. #4
    Join Date
    Aug 2007
    There is actually almost no data in the database (maybe three records in total) because I had to clear it out to restructure it. Since I'm still building the data never get terribly numerous.

    I am on PHP5.3, yes, but this was working on that platform. Also, setting debug to zero gives me a white screen for anything involving the project_links controller. No error messages at all. Debug at 1 or 2 give me the error message again.
    It's strange that it should be doing this. The relationship of this ProjectLink model to the Project model has not changed at all.
    Additionally, I gather that Cake only loads references to a model, each model is effectively singular and so MyModel1->MyModel2 === MyModel3->MyModel2 or am I mistaken. Were this the case then there would be lots of references but they would eventually peter out because even for a complex web of relationships, the references would mean that there would be no extra objects (or even references for that matter) loaded into the memory.
    If anything I have actually reduced the number of models in the programme so I don't see why I am getting this problem. Alas! MacGDBp has not been of much use either.

    How could I go about debugging this I wonder?

  5. #5
    Join Date
    Nov 2008
    Have you recently installed xdebug? It is this which is setting the 100 limit on recursion. I'm wondering if this error was always there due to the extra E_STRICT errors cake causes with 5.3, but that xdebug's 100 limit is not enough to allow debugger.php to finish up handling the errors (which is why I suggested turning debugging off, but of course that also hides PHP's errors so is entirely unhelpful).
    The first rule of Tautology Club is the first rule of Tautology Club.

  6. #6
    Join Date
    Aug 2007
    Quote Originally Posted by Mindzai View Post
    Have you recently installed xdebug? It is this which is setting the 100 limit on recursion.
    I've had xdebug going on this project for at least the last two/two and a half months so it's not a recent thing. This model was working with xdebug installed before. It is xdebug which is probably setting (or at least detecting) this limit.

    Cake shouldn't be recursing this deeply anyway, should it?
    It is fairly strange that the debug cycle is happening around the 99th function in the spiral. This suggests that Cake was breaking out of this cycle before the 100th function limit which means it wasn't an infinite loop. C'est un peu bizarre.

    I think that there must be a problem anyway because if I turn debugging off, I just get a white screen and no errors (because I assume it sets display_errors to 0). Grr.

  7. #7
    Join Date
    Aug 2007
    Purely for interest's sake, I found the following which seems to relate to my problem in some ways...:


  8. #8
    Join Date
    Aug 2007
    And just in case we thought it was just an xdebug issue, on disabling xdebug I get the following:

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 261900 bytes) in [...]/cake/libs/debugger.php on line 428

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12538 seconds
  • Memory Usage 3,162KB
  • Queries Executed 13 (?)
More Information
Template Usage (32):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates