PHP sf.1.4 Propel 1.6: memory leak when doing loops

I am working with symfony 1.4 + propel 1.6 and I want to export (index) my entire user database to ElasticSearch.

I wrote the entire script and everything works fine except for one problem. I am doing a loop that repeats about 20,000 times and every time the memory increases,

The problem is that it shouldn't, because I'm destroying all references.

I think Propel is leaving somewhere a static reference to every object I create. Can't find it because I have already disabled instance merging.

Has anyone had the same problem? Maybe someone has an idea how I can debug PHP memory limits? (webgrind doesnt) I've spent the last few hours on this part of debugging the code and still can't fix it.

// optimizations
    gc_enable();
    Propel::getConnection()->useDebug(false);
    Propel::disableInstancePooling();
// the while
    $offset = 0;
    $perpage = 10;
    $c = SearchUserQuery::create()->limit($perpage);
    do {
        $rs = SearchUserPeer::doSelectStmt($c);
        while ($row = $rs->fetch(PDO::FETCH_NUM))
        {
            $instance = new SearchUser();
            $instance->hydrate($row);
            $data = $instance->toElastic(); // this line makes a lot of memory leak
            $_document = new Elastica\Document($instance->getPrimaryKey(), $data);
            $_type->addDocument($_document);
            unset($_document, $instance);
        }
        $c->offset($offset += $perpage);
    } while( $rs->rowCount() );

      

The $ instance-> toElastic function is like this:

public function toElastic()
{
    return Array(
        'profile' => $this->toArray(BasePeer::TYPE_COLNAME, false),
        'info' => $this->getUserInfo()->toArray(BasePeer::TYPE_COLNAME, false),
        'branches' => $this->getElasticBranches(),
    );
}

/**
 * @return array(id,name)
 */
public function getElasticBranches()
{
    $branches = Array();
    foreach ($this->getsfGuardUser()->getUserBranchs() as $branch)
        $branches[] = Array(
            'id' => $branch->getBranchId(),
            'name' => $branch->getName()
        );
    return $branches;
}

      

+3


source to share


1 answer


Have you tried this before disarming?

// garbage collector problem in PHP 5.3
$instance->clearAllReferences(true);

// remove the variable content before removing the address (with unset)
$instance = null;
$_document = null;
$_type = null;

      



You can get more advice from this answer . Looks at 3 links, there are really interesting ones even if one of them is in French.

+5


source







All Articles