Serg S
Serg S

Reputation: 21

Update price, status stock, post status form CSV (more 20k products) in WOOCOMMERCE (Memory runs out on 3000 products)

I use the construction for read csv file (about 25000 lines) in my method update() of my class

if(($handle = fopen($this->csv_url, 'r')) !== false) {

        $row = 0;

        while(($data = fgetcsv($handle)) !== false)
        {
            if ($row === 0) { $row++; continue; }

            // Doing update a few meta in current product
            // I detect product by sku

            unset($data);
            $row++;
        }

        fclose($handle);
    }

Memory runs out on 3000 products. (250MB setup in php.ini file)

Does anyone have any ideas? Sorry for my English.

Upvotes: 0

Views: 142

Answers (1)

Serg S
Serg S

Reputation: 21

I have long resolved this issue; here is what I found:

In each loop iteration (I did it every 20), I use this function wp_cache_flush().

As a result, I have 86 MB of used memory without accumulation:

screenshot

Upvotes: 2

Related Questions