如何释放线程中使用的Symfony(PHP)内核?
在PHP7.0.2中,开发一个symfony2命令,在该命令中创建两级线程(fork) 有一个容器类实例化MyWorker类(扩展自Worker),并为$workers数组中的每个MyWorker元素调用start()函数 通过调用MyWorker的函数start(),函数运行时创建了一个Symfony实例,在存储库中搜索数据,每个MyWorker创建了属于MyThread类的5个子函数,并称为调用run函数的函数start() 在MyThread的run函数中,Symfony再次被实例化(我没有找到通过父实例实现的方法) 问题在于,当反复调用process()函数(超过200次)时,会生成以下内存错误:如何释放线程中使用的Symfony(PHP)内核?,php,multithreading,symfony,Php,Multithreading,Symfony,在PHP7.0.2中,开发一个symfony2命令,在该命令中创建两级线程(fork) 有一个容器类实例化MyWorker类(扩展自Worker),并为$workers数组中的每个MyWorker元素调用start()函数 通过调用MyWorker的函数start(),函数运行时创建了一个Symfony实例,在存储库中搜索数据,每个MyWorker创建了属于MyThread类的5个子函数,并称为调用run函数的函数start() 在MyThread的run函数中,Symfony再次被实例化(我没
mmap () failed: [12] Can not allocate memory. Fatal error: Out of memory (allocated 2820669440) (tried to allocate 32768 bytes) in /srv/www/leadpro.com/current/vendor/symfony/symfony/src/Symfony/Component/Debug/Exception/OutOfMemoryException.php on line 1
我假设必须生成错误,因为symfony实例没有在worker和线程中释放
如果有人能提出解决方案,我将不胜感激
class MyWorker extends \Worker
{
protected $container;
protected $document_manager;
protected $id;
public function __construct ( $param )
{
$id = $param['id'];
//... Set other parameters
}
public function setDoctrineManagerInWorker()
{
//Set require Autoload and AppKernel
require_once __DIR__.'/../../../../app/autoload.php';
require_once __DIR__.'/../../../../app/AppKernel.php';
//Creating a new AppKernel with the given environment
$kernel = new \AppKernel( 'dev', 1 );
//Loading the Cache and Classes
$kernel->loadClassCache();
$kernel->boot();
//Set container
$container = $kernel->getContainer();
//Set document manager
$document_manager = $kernel->getContainer()->get('doctrine')->getManager();
}
public function run()
{
$this->setDoctrineManagerInWorker();
//... Aqui se aplica la logica para acceder a los repositorios
$worker = $this->document_manager->getRepository('MyBundle:Worker')->find( $this->getId() );
//...
for ( $i = 0; $i < 5; $i++ )
{
$thread = new MyThread( $param );
$thread->start();
$thread->join();
}
}
}
class MyThread extends \Thread
{
protected $container;
protected $document_manager;
public function __construct ( $param )
{
//... Set parameters
}
public function setDoctrineManagerInThread()
{
//Set require Autoload and AppKernel
require_once __DIR__.'/../../../../app/autoload.php';
require_once __DIR__.'/../../../../app/AppKernel.php';
$kernel = new \AppKernel( 'dev', 1 );
//Loading the Cache and Classes
$kernel->loadClassCache();
$kernel->boot();
//Set container
$this->container = $kernel->getContainer();
//Set document manager
$this->document_manager= $kernel->getContainer()->get('doctrine_mongodb')->getManager();
}
public function run()
{
$this->setDoctrineManagerInThread();
//... Logical processing of repositories
$thread = $this->document_manager->getRepository('MyBundle:Thread')->findAll();
//...
}
}
mmap () failed: [12] Can not allocate memory. Fatal error: Out of memory (allocated 2820669440) (tried to allocate 32768 bytes) in /srv/www/leadpro.com/current/vendor/symfony/symfony/src/Symfony/Component/Debug/Exception/OutOfMemoryException.php on line 1