0

Doctrine 2 /Symfony を使用したバッチ処理スクリプト中にメモリ リークの問題が発生しました。

最初: エンティティ マネージャーを適切に管理してメモリ リークを回避する方法を認識しており、何らかの理由でライブ サーバーはこの問題に遭遇することなく次のコードを実行できます。ただし、ローカル開発環境 (PHP 5.4.7) で次のコマンドを実行すると、メモリの使用量が急増します。

編集:

私は今完全に途方に暮れているので、この問題を引き起こしている可能性のあるphp ini、apache、osx、mysql構成はありますか。

コードは両方の場所で同じであることに注意してください。したがって、この違いの原因は、私が知らない何らかのログ (x-debug または SQL の自動ログ) だけです。

ライブ サーバーはローカルで PHP 5.4.6 と 5.4.7 を実行しています ライブ サーバーは centos 6 とローカルで OSX を実行しています

デバッグをオフにして、prod モードで次のコマンドを実行しています...

<?php

namespace Vendor\Bundle\MemoryTestBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MemTestCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('mem:test')
            ->setDescription('Shows memory use ballooning out of control');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $em = $this->getContainer()->get('doctrine.orm.entity_manager');

        $q = $em->createQuery('SELECT s FROM VendorMemoryTestBundle:SimpleEntity s');
        $iterableResult = $q->iterate();

        $i = 0;

        while (($row = $iterableResult->next()) !== false) {
            $i++;
            if ($i%50 == 0){
                echo sprintf('Memory usage: %01.0fKB.', memory_get_usage(true) / 1024) . PHP_EOL;
                $em->clear();
            }
            $em->detach($row[0]);
        }
    }
}

出力

Memory usage: 72192KB.
Memory usage: 72448KB.
Memory usage: 72448KB.
Memory usage: 72704KB.
Memory usage: 73216KB.
Memory usage: 73472KB.
Memory usage: 73472KB.
Memory usage: 73728KB.
Memory usage: 73728KB.
Memory usage: 73984KB.
Memory usage: 73984KB.
Memory usage: 74240KB.
etc...
4

1 に答える 1

0

ここで説明されているように: php / symfony / doctrineのメモリリーク?

デバッグ環境では、Symfonyはすべてのクエリをログに記録します。オプション「profiler:false」を手動で設定する必要があります。

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

それが役に立ったかどうか教えてください。リンク先のページには他にもいくつかの推奨事項があります。あなたはそれらをチェックしたいかもしれません。

于 2012-12-14T08:27:22.283 に答える