Hi im trying to code a funktion that will import trailers from a remote server The code is matching product in our magento store with the trailers on the trailer server . The problem is that the script eating up all memory. is there any way of optimize this to not consume memory .
here are my function
function getTrailers() {
echo "<pre>
";
$this->_acquireLock();
$_productCollection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('attribute_set_id', array('eq' => '9'));
//->addAttributeToFilter('Sku', array('eq' => '843594'));
$this->_logLine(sprintf("Starting import of Trailers" ));
$i=0;
$server = "http://trailer.server.com/trailers";
foreach($_productCollection as $product) {
$thispro = Mage::getModel('catalog/product')->load($product->getId());
$attributeValue = $thispro->getFaktaId();
//echo memory_get_usage() . "<br>
";
//echo memory_get_peak_usage() . "<br>
";
if($thispro->getMainTrailer()=="") {
if($attributeValue != "") {
$im = $attributeValue.".mp4";
$url = $server.$im;
$exist = $this->file_exists_remote($url);
if($exist) {
$i++;
$product->setMainTrailer($url);
$product->save();
} else {
}
}
}
}
$this->_logLine(sprintf("Imported %d Trailers...", $i));
$this->_releaseLock();
echo "</pre>
";
}