0

ランダムな製品、注文、および顧客を作成することにより、大規模な店舗を複製するモジュールを 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 モデルを使用した後のクリーンアップ方法に関するヒントはありますか?

4

1 に答える 1