php/symfony/doctrine memory leak?

后端 未结 9 1689
旧时难觅i
旧时难觅i 2020-11-30 00:34

I\'m having problems with a batch insertion of objects into a database using symfony 1.4 and doctrine 1.2.

My model has a certain kind of object called \"Sector\", e

相关标签:
9条回答
  • 2020-11-30 01:16

    Try to unset($cupo); after every saving. This should be help. An other thing is to split the script and do some batch processing.

    0 讨论(0)
  • 2020-11-30 01:17

    What is working for me is calling the free method like this:

    $cupo->save();
    $cupo->free(true); // free also the related components
    unset($cupo);
    
    0 讨论(0)
  • 2020-11-30 01:26

    Tried doing

    $cupo->save();
    $cupo->free();
    $cupo = null;
    

    (But substituting my code) And I'm still getting memory overflows. Any other ideas, SO?

    Update:

    I created a new environment in my databases.yml, that looks like:

    all:
      doctrine:
        class: sfDoctrineDatabase
        param:
          dsn: 'mysql:host=localhost;dbname=.......'
          username: .....
          password: .....
          profiler: false
    

    The profiler: false entry disables doctrine's query logging, that normally keeps a copy of every query you make. It didn't stop the memory leakage, but I was able to get about twice as far through my data importing as I was without it.

    Update 2

    I added

    Doctrine_Manager::connection()->setAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS, true ); 
    

    before running my queries, and changed

    $cupo = null;
    

    to

    unset($cupo);
    

    And now my script has been churning away happily. I'm pretty sure it will finish without running out of RAM this time.

    Update 3

    Yup. That's the winning combo.

    0 讨论(0)
  • 2020-11-30 01:26

    Doctrine leaks and there's not much you can do about it. Make sure you use $q->free() whenever applicable to minimize the effect. Doctrine is not meant for maintenance scripts. The only way to work around this problem is to break you script to parts which will perform part of the task. One way to do that is to add a start parameter to your script and after a certain amount of objects had been processed, the script redirects to itself with a higher start value. This works well for me although it makes writing maintenance scripts more cumbersome.

    0 讨论(0)
  • 2020-11-30 01:34

    I have just did "daemonized" script with symfony 1.4 and setting the following stopped the memory hogging:

    sfConfig::set('sf_debug', false);
    
    0 讨论(0)
  • 2020-11-30 01:37

    Try to break circular reference which usually cause memory leaks with

    $cupo->save();
    
    $cupo->free(); //this call
    

    as described in Doctrine manual.

    0 讨论(0)
提交回复
热议问题