简体   繁体   English

Magento批量订单,产品和客户创造

[英]Magento Mass Order, Product and Customer Creation

I've created a module in Magento that replicates large stores by creating random products, orders and customers. 我在Magento中创建了一个模块,该模块通过创建随机产品,订单和客户来复制大型商店。 The data creation described above takes place in my model which is straight PHP code. 上面描述的数据创建在我的模型中进行,该模型是直接的PHP代码。 I'm experiencing serious memory management issues despite making use of PHP's unset() and Magento's clearInstance(). 尽管使用了PHP的unset()和Magento的clearInstance(),但我仍遇到严重的内存管理问题。 I've commented ~10 lines of code below showing how my attempt to free memory fails. 我在下面评论了大约10行代码,这些代码显示了释放内存的尝试失败的方式。

/**
 * Creates random customers.
 *
 * @param  int $offset, used to make sure the ids created are unique
 */
protected function _createCustomer($offset)
{
    // Create some random customer information
    $firstName = strtolower($_firstNames[array_rand($_firstNames, 1)]);
    $lastName  = strtolower($_lastNames[array_rand($_lastNames, 1)]);
    $customerEmail = $firstName[0] . $lastName.time().$offset."@weliketopumpit.com";

    // Retrieve customer model
    $customer = Mage::getModel('customer/customer')
        ->setWebsiteId(Mage::app()->getWebsite()->getId())
        ->loadByEmail($customerEmail);

    // Populate model and save it
    if(!$customer->getId()){
        $customer
            ->setEmail    ($customerEmail)
            ->setFirstname($firstName)
            ->setLastname ($lastName)
            ->setPassword ('password1')
            ->setCreatedAt(rand($this->_startDate, time()));
    }
    $customer->save();
    $customer->setConfirmation(null);
    $customer->save();

    $this->log(memory_get_usage() . "\n"); // Returns 17306840
    $customer->clearInstance();            // Called to clean up the object
    $this->log(memory_get_usage());        // Returns 17307304, memory wasn't unallocated

    debug_zval_dump($customer);            //Returns a refcount(2)
}

Calling unset in place of clearInstance() produces the same result. 在clearInstance()处调用unset会产生相同的结果。 Any tips on how to clean up after using Magento models? 使用Magento模型后如何清理的任何提示?

I would use the resource instead of the model, it's gonna be quicker and less memory costly. 我将使用资源而不是模型,它将更快,更少的内存开销。 If that's not good enough, convert it to raw sql, EAV is not that complex when it comes to inserting records. 如果这还不够好,请将其转换为原始sql,则在插入记录时,EAV并不那么复杂。

An alternative way I would also try is: http://ringsdorff.net/2009/07/23/guest-post-fix-for-memory-leaks-in-magento/ But that's not recommended for production, so I would build a custom Customer model that incorporates those desctructors and just use the new model in my script leaving everything else (production) run on normal model. 我也会尝试的另一种方法是: http : //ringsdorff.net/2009/07/23/guest-post-fix-for-memory-leaks-in-magento/但这不建议用于生产环境,因此我会进行构建这包含了这些desctructors,只是使用在我的剧本把其他所有的(生产)的新模型的自定义客户模式正常运行模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM