Tập lệnh của tôi nhập tệp Excel vào cơ sở dữ liệu sản phẩm để cập nhật số lượng sản phẩm mới, v.v.
Tôi đang gặp vấn đề về bộ nhớ và tôi đã thử nâng giới hạn bộ nhớ lên mức tối đa [800MB+]. Tôi đã thử giải quyết các biến để phát hành bộ nhớ giữa các vòng lặp nhưng tôi vẫn hết bộ nhớ. Tôi đã thử đặt thời gian chờ thành vô hạn nhưng nó chắc chắn là vấn đề bộ nhớ.
MSG lỗi từ tệp nhật ký: Lỗi nghiêm trọng: Kích thước bộ nhớ được phép là 851443712 byte cạn kiệt [đã cố gắng phân bổ 71 byte]
Không có tập lệnh nào được chứa trong một hàm. Nếu tôi tạo chính cho vòng lặp bên trong một hàm và liên tục gọi hàm đó sẽ giúp thu thập rác và xóa bộ nhớ? Bất kỳ sự giúp đỡ hoặc hướng dẫn sẽ được đánh giá cao.
Nhập tập lệnh:
error_reporting[ E_ALL & ~E_NOTICE ];
ini_set['memory_limit', '812M'];
set_time_limit[0];
/* Config Start */
define['BasePath', '/home/xxxxx/public_html'];
define['CfgMagentoPath', BasePath];
define['CfgCategoryMapDBxls', BasePath."/xxxx/Shdddddd.xls"];
define['CfgVenderDBxls', BasePath."/xxxx/xxxxxx.xls"];
define['CfgReportEmail', ""];
/* Config End */
require_once[CfgMagentoPath . '/app/Mage.php'];
Mage::app[];
//$app = Mage::app['default'];
//Mage::app[]->setCurrentStore[Mage_Core_Model_App::ADMIN_STORE_ID];
require_once[BasePath.'/xxxxx/xxxx/libs/mage.func-inc.php'];
require_once[BasePath.'/xxxxx/xxxxx/libs/excel-read.class.php'];
//Alert Arrays
$AAnotmapped = array[];
$AAnewproducts = array[];
$AApriceupdated = array[];
$AAimgerror = array[];
$PriceErrors = array[];
$SkipCat = false;
//Create Mapped Cats - In Magento
$excel = new ExcelReader[CfgCategoryMapDBxls,"UTF-8"];
$CM = $excel->getWorksheetData['Sheet1'];
if[!$SkipCat]{
echo "======== Generating Catagory Maps ===========\n\n";
CatMap_Create[$CM];
echo "======== ============================== ===========\n\n";
}
//Start Item Read
$excel = new ExcelReader[CfgVenderDBxls,"UTF-8"];
$IT = $excel->getWorksheetData['New_DATA'];
$ITcnt = 0;
$ITtotal = count[$IT];
foreach[$IT as $ItemRow]{
$ITcnt++;
$cSKU = $ItemRow['ITEM'];
$cProductName = Clean_Data[$ItemRow['ALTSHORTDESC']];
$cCatName = Clean_Data[$ItemRow['CATEGORY']];
$cManuf = Clean_Data[$ItemRow['MANUFACTURER']];
$cShortDesc = Clean_Data[$ItemRow['SHORTDESC']];
$cLongDesc = Clean_Data[$ItemRow['LONGDESC']];
$cUPC = Prod_GetUPC[$ItemRow['UPC'], $ItemRow['ALTUPC']];
$cStockQty = $ItemRow['QTY'];
$cWeight = Prod_GetWeight[$ItemRow['WEIGHT'], $ItemRow['ALTWEIGHT']];
$cPrice = Prod_FigurePrice[$ItemRow['COST'], $ItemRow['MSRP'], $ItemRow['MAP']];
$cCost = $ItemRow['COST'];
//Locate Catagory Map Magento ID
$mCatId = CatMap_Search[$CM, $ItemRow['CATEGORY']];
//Now Create Product
if[$mCatId > 0 && $cProductName != ""]{
echo date["m.d.y g:i a"]."\t[$ITcnt / $ITtotal] Working On: " . $cProductName . " - SKU: $cSKU\n";
$ProdID = Prod_GetIDfromSKU[$cSKU];
if[$ProdID > 0]{
if[Prod_Update[$ProdID, $cCost, $cStockQty, $cWeight, $cUPC]]{
echo "Updated: $cProductName\n";
$ITindex++;
}
}else{
Prod_Create[$cSKU, $cProductName, $cManuf, $cPrice, $cCost, $cWeight, $cShortDesc, $cLongDesc, $cStockQty, $cUPC, $mCatId];
echo "Created: $cProductName to Catagory: $mCatId\n";
echo "$cShortDesc\n\n";
$ProdID = Prod_GetIDfromSKU[$cSKU];
}
if[$cPrice xpath['//item'] as $key => &$item] {
// ...
// Clear item and other variables from memory after each loop, or you will run out of it really fast.
$item = NULL;
}
Programming Language: PHP