www.webdeveloper.com
Results 1 to 8 of 8

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

  1. #1
    Join Date
    Aug 2007
    Location
    London
    Posts
    410

    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 {
        var 
    $name "ProjectLink";
        
        var 
    $actsAs = array("Containable");
        
        var 
    $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
    Location
    Ankh-Morpork
    Posts
    19,537
    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?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    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?

  4. #4
    Join Date
    Aug 2007
    Location
    London
    Posts
    410
    @NogDog:
    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.

    @Mindzai:
    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
    Posts
    2,477
    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).

  6. #6
    Join Date
    Aug 2007
    Location
    London
    Posts
    410
    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
    Location
    London
    Posts
    410
    Purely for interest's sake, I found the following which seems to relate to my problem in some ways...:

    https://trac.cakephp.org/ticket/4415

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

    Code:
    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



Recent Articles