I've got a problem with a script which is syncing warehouse-system with e-commerce Magento.
Script is updating Magento's records directly to the database, price and quantity.
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 8309 bytes) in /lib/Zend/Cache/Backend/File.php on line 962
It's obviously memory-eating script, is there any way to decrease it's hungriness?:)
I can increase capacity of the memory but it won't be solution, as the moment there is about free 700MBs of memory.
There is about 1000 of lines in .csv file.
<?
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$count = 0;
$file = fopen(MAGENTO . '/SECRET-FOLDER-WITH-CSV/quantity-and-prices.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
if ($count == 0) {
foreach ($line as $key => $value) {
$cols[$value] = $key;
}
}
$count++;
if ($count == 1)
continue;
#Convert the lines to cols
if ($count > 0) {
foreach ($cols as $col => $value) {
unset(${$col});
${$col} = $line[$value];
}
}
// Check if SKU exists
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
if ($product) {
$productId = $product->getIdBySku($sku);
$stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($productId);
$stockItemId = $stockItem->getId();
$stock = array();
$newprice = $line[2];
$product->setPrice($newprice)->save();
if (!$stockItemId) {
$stockItem->setData('product_id', $product->getId());
$stockItem->setData('stock_id', 1);
} else {
$stock = $stockItem->getData();
}
foreach ($cols as $col => $value) {
$stock[$col] = $line[$value];
}
foreach ($stock as $field => $value) {
$stockItem->setData($field, $value ? $value : 0);
}
$stockItem->save();
unset($stockItem);
unset($product);
}
echo "<br />Stock updated $sku";
}
fclose($file);