Symfony任务-内存泄漏 [英] Symfony task - memory leak

查看:61
本文介绍了Symfony任务-内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个symfony任务来填充样本数据数据库.这是一段示例代码:

I wrote a symfony task to fill a database of sample data. Here's a sample piece of code:

gc_enable();
Propel::disableInstancePooling();

public function test()
{
    for($i = 0; $i < 10000; $i++) {
        $this->doIt($i);
    }
}

public function doIt($i)
{
    $user = new User();
    $user->setUsername('user' . $i . "@example.com");
    $user->setPassword('test');
    $user->setFirstName('firstname' . $i);
    $user->setLastName('surname' . rand(0, 1000));

    $user->save();
    $user->clearAllReferences(true);
    $user = null;
    gc_collect_cycles();
}

如何限制内存使用量?

推荐答案

您在 SO上的另一个线程.

这是关于

And here is a really good blog post about memory leak using propel. It's in french, but it's really interesting.

而且,如果您正在处理大数据(例如海量导入),则还应该查看pcntl_fork(请参见要点). pcntl_fork在Windows上不起作用.我使用这种方法来处理大量的导入操作,它的速度非常快,而且不会占用您的所有内存.

And, if you are working on big data (such as mass import) you should also took a look at pcntl_fork (see this gist). pcntl_fork doesn't work on Windows. I used this method to deal with big import and it's really fast and don't eat all your memory.

这篇关于Symfony任务-内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆