簡體   English   中英

Magento批量訂單,產品和客戶創造

[英]Magento Mass Order, Product and Customer Creation

我在Magento中創建了一個模塊,該模塊通過創建隨機產品,訂單和客戶來復制大型商店。 上面描述的數據創建在我的模型中進行,該模型是直接的PHP代碼。 盡管使用了PHP的unset()和Magento的clearInstance(),但我仍遇到嚴重的內存管理問題。 我在下面評論了大約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)
}

在clearInstance()處調用unset會產生相同的結果。 使用Magento模型后如何清理的任何提示?

我將使用資源而不是模型,它將更快,更少的內存開銷。 如果這還不夠好,請將其轉換為原始sql,則在插入記錄時,EAV並不那么復雜。

我也會嘗試的另一種方法是: 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