Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php symfony2中的批处理_Php_Symfony_Batch Processing - Fatal编程技术网

Php symfony2中的批处理

Php symfony2中的批处理,php,symfony,batch-processing,Php,Symfony,Batch Processing,我在symfony2中创建了一个自定义控制台命令。此命令将调用api为所有用户查找合适的作业。然后我会得到这样一个错误。 我的代码如下: $em = $this->getContainer()->get('doctrine')->getEntityManager('default'); $user = $em->getRepository('EnsUserBundle:User')->findAll(); f

我在symfony2中创建了一个自定义控制台命令。此命令将调用api为所有用户查找合适的作业。然后我会得到这样一个错误。 我的代码如下:

 $em = $this->getContainer()->get('doctrine')->getEntityManager('default');
            $user = $em->getRepository('EnsUserBundle:User')->findAll();
                foreach ($user as $user) 
                {
                    .....
                    $em->flush();
                }
            }
        }

然后我想为每个用户清除entitymanager

$em = $this->getContainer()->get('doctrine')->getEntityManager('default');
                $user = $em->getRepository('EnsUserBundle:User')->findAll();
                    foreach ($user as $user) 
                    {
                        .....
                        $em->flush();
                        $em->clear();
                    }
                }
            }
这将导致一个错误: 然后我尝试使用批处理过程:

$em = $this->getContainer()->get('doctrine')->getEntityManager('default');
        $user = $em->getRepository('EnsUserBundle:User')->findAll();
        $iterableResult = $em->getRepository('EnsUserBundle:User')->findAll()->iterate();
        while (($row = $iterableResult->next()) !== false) 
        {
            foreach ($user as $user) 
            {
                .....
                $em->flush();
                $em->clear();
            }
            $em->detach($row[0]);
        }
    }
但这会导致一个错误

那么,你有什么好的建议吗? 谢谢大家!

您可以尝试:

  • 增加脚本在php内部消耗的最大内存:php.ini
    内存限制=512M

  • 当对象达到XX项时刷新对象(例如:每100项)。您可以在每次刷新管理器时清除它


感谢您的回复。但正如你在第二张截图中看到的。每次我试图清除它,我都会得到这个错误。你知道为什么吗?我建议你每次清除entityManager(批量处理)。为什么需要使用iterate()函数并将其包含到两个循环中?也许我不需要。因为我看到了这个。所以我想这可能对我有帮助。