嗨即时尝试代码的功能,将从远程服务器导入预告片 该代码是匹配我们的magento商店中的产品与预告片服务器上的预告片。 问题在于脚本吃掉了所有的内存。有什么方法可以优化这个不消耗内存。Php脚本内存不足
这里是我的功能
function getTrailers() {
echo "<pre>\n";
$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>\n";
//echo memory_get_peak_usage() . "<br>\n";
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>\n";
}
女巫梅托德可我用在每个循环 –