开发者

use symfony form validator for Bulk-Insert

i receive an CSV File from the User and I want to insert it into the Database. I want to use the Form Validation:

$pf = new ProductForm();
$old_memory_usage = 0;

while($data = $csvreader->read())
{
  $mem = memory_get_usage() / 1024;
  echo "Memory-Usage: " . $mem . " KB; Mem-Diff: " . $mem - $old_memory_usage . "\n";
  $old_memory_usage = $mem;

  $p = new Product();
  $p->fromArray($data);
  $pf->bind($p->toA开发者_如何学编程rray(), array());
  if($pf->isValid())
  {
    $p->save();
  }
  else
  {
    //display error message to the user
  }
}

This works fine when isValid() returns true. The Memory Difference is 0 KB. But if there is an Error in the "form" the memory-difference is 6-7 KB. So I get an allowed_memory error when the CSV-File is very huge.

I tryed to free the form like:

unset($pf)
$pf = null;
$pf = new ProductForm();

no success. It is just worse!

ans ideas? thx!


You can disable doctrine profiler in your databse yml:

  dev:
    doctrine:
      class: sfDoctrineDatabase
      param:
        profiler: false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜