在php中运行程序时内存不足

在php中运行程序时内存不足,php,xml-parsing,simplexml,Php,Xml Parsing,Simplexml,我正在运行两个几乎相同的程序,唯一的例外是一个只需要查看最低价格,第二个需要查看最低4个价格,然后得到平均价格。我的问题是,在运行第二个程序时,出现了一个内存不足的php致命错误。我的主机提供商为我设置了3000M的内存限制,但我仍然收到错误。 以下是第一个程序的代码: $parsed_xml = amazon_xml($isbn); $current = $parsed_xml->ListMatchingProductsResult->Products->Produ

我正在运行两个几乎相同的程序,唯一的例外是一个只需要查看最低价格,第二个需要查看最低4个价格,然后得到平均价格。我的问题是,在运行第二个程序时,出现了一个内存不足的php致命错误。我的主机提供商为我设置了3000M的内存限制,但我仍然收到错误。 以下是第一个程序的代码:

    $parsed_xml = amazon_xml($isbn);

$current = $parsed_xml->ListMatchingProductsResult->Products->Product;
$asin = $current->Identifiers->MarketplaceASIN->ASIN;
//print_r($asin);

// get information based on the items ASIN
$price_xml = amazonPrice_xml($asin, $ItemCondition);
$currentPrice = $price_xml ->GetLowestOfferListingsForASINResult->Product->LowestOfferListings->LowestOfferListing;
$listPrice = $currentPrice->Price->ListingPrice->Amount;

// check to see if there are values
if(!empty($listPrice))
{  
            //print_r($listPrice); die;
//if($currentPrice->Price->ListingPrice->Amount > 0) {
    while(count($lowestPrices) < 2)
    {

            foreach($currentPrice as $offer){ 
                $totalFeedback = $offer->SellerFeedbackCount;

                $condition = $offer->Qualifiers->ItemSubcondition;

                //amazon condition matching algorithm (so we can match our condition up against amazons conditions)
                switch ($condition) {
                case "New":
                    $amazonCondition = 5;
                    break;
                case "Mint":
                    $amazonCondition = 4;
                    break;
                case "VeryGood":
                    $amazonCondition = 3;
                    break;
                case "Good":
                    $amazonCondition = 2;
                    break;
                case "Acceptable":
                    $amazonCondition = 1;
                    break;
                default:
                    $amazonCondition = 0;
                } // end of switch statement

            //echo $condition . "|" . $ourCondition . "|" . $amazonCondition . "|" . count($lowestPrices) . "|" . $totalFeedback . "|" . $merchantId . "<br/>";

            /* default lowest 1 */
                if(count($lowestPricesDefault[$a] <2)){
                $lowestPricesDefault[$a] = str_replace('$','',$offer->Price->ListingPrice->Amount);
                $a++;
                }

                if( ($ourCondition <= $amazonCondition) && ($totalFeedback >= 1500) &&  (count($lowestPrices) <2) )
                {
                $lowestPrices[$x] = str_replace('$','',$offer->Price->ListingPrice->Amount);
                $x++;
                }

            }
        $z++;
    }


    if(count($lowestPrices) > 0){
        $avgPrice = (array_sum($lowestPrices)/count($lowestPrices)) - .10;
        $source = "Amazon Condition Price";
    }else{
        //$avgPrice = $listPrice - ($listPrice * 0.25);
        $avgPrice = (array_sum($lowestPricesDefault)/count($lowestPricesDefault)) - .10;
        $source = "Default Pricing";
    }

    //make sure avg price is atleast 5.50, >236% of follett price, and >=200% of our cost
    if($avgPrice < ($follettPrice * 2.37)){
        $avgPrice = $follettPrice * 2.37;
        $source = "Follett Pricing";
    }
    if($avgPrice < ($row['cost'] * 2)){
        $avgPrice = $row['cost'] * 2;
        $source = "Double Cost";
    }
    if($avgPrice < 5.50){
        $avgPrice = 5.50;
        $source = "Lowest Base Cost";
    }

    //update Prices
    $conn->query("UPDATE inventory SET ourPrice = $avgPrice WHERE sku=" . $row['sku']);
$parsed_xml=amazon_xml($isbn);
$current=$parsed_xml->ListMatchingProductsResult->Products->Products;
$asin=$current->Identifiers->MarketplaceASIN->asin;
//打印(asin);
//根据ASIN中的项目获取信息
$price\u xml=amazonPrice\u xml($asin$ItemCondition);
$currentPrice=$price_xml->getLowstofferistingsforasinResult->Product->Lowstofferistings->Lowstofferistings;
$listPrice=$currentPrice->Price->ListingPrice->Amount;
//检查是否有值
如果(!空($listPrice))
{  
//印刷品($listPrice);模具;
//如果($currentPrice->Price->ListingPrice->Amount>0){
而(计数($lowerstprice)<2)
{
foreach($currentPrice作为$offer){
$totalFeedback=$offer->SellerFeedbackCount;
$condition=$offer->Qualifiers->ItemSubcondition;
//amazon条件匹配算法(因此我们可以将我们的条件与amazon条件进行匹配)
开关($条件){
案例“新”:
$amazonCondition=5;
打破
“铸币厂”一案:
$amazonCondition=4;
打破
“VeryGood”案:
$amazonCondition=3;
打破
案例“好”:
$amazonCondition=2;
打破
案例“可接受”:
$amazonCondition=1;
打破
违约:
$amazonCondition=0;
}//开关结束语句
//echo$condition.“|”。$ourCondition.“|”。$amazonCondition.“|”。count($lowerstprices)。“|”。$totalFeedback.“|”。$merchantId.
”; /*默认最低1*/ 如果(计数($lowerstpricesdefault[$a]价格->列表价格->金额); $a++; } 如果($ourCondition=1500)和($lowerstprices)价格->列表价格->金额); $x++; } } $z++; } 如果(计数($lowerstprice)>0){ $avgPrice=(数组和($lowerstrices)/计数($lowerstrices))-.10; $source=“亚马逊条件价格”; }否则{ //$avgPrice=$listPrice-($listPrice*0.25); $avgPrice=(数组和($lowestPricesDefault)/count($lowestPricesDefault))-.10; $source=“默认定价”; } //确保平均价格至少为5.50,>follett价格的236%,且>=我们成本的200% 如果($avgPrice<($follettPrice*2.37)){ $avgPrice=$follettPrice*2.37; $source=“Follett定价”; } 如果($avgPrice<($row['cost']*2)){ $avgPrice=$row['cost']*2; $source=“双重成本”; } 如果($avgPrice<5.50){ $avgPrice=5.50; $source=“最低基本成本”; } //更新价格 $conn->query(“更新库存设置ourPrice=$avgPrice,其中sku=”.$row['sku']);
下面是第二个程序:

    $parsed_xml = amazon_xml($isbn);

$current = $parsed_xml->ListMatchingProductsResult->Products->Product;
$asin = $current->Identifiers->MarketplaceASIN->ASIN;

// get information based on the items ASIN
$price_xml = amazonPrice_xml($asin, $ItemCondition);
$currentPrice = $price_xml ->GetLowestOfferListingsForASINResult->Product->LowestOfferListings->LowestOfferListing;
$listPrice = $currentPrice->Price->ListingPrice->Amount;

// check to see if there are values
if(!empty($listPrice))
{  
//if($price_xml) {
    while(count($lowestPrices) < 4 ) // changed count to 4 per loralee's email 5-1-2012
    {


        foreach($currentPrice as $offer){
            $totalFeedback = $offer->SellerFeedbackCount;

            $condition = $offer->Qualifiers->ItemSubcondition;

                //amazon condition matching algorithm (so we can match our condition up against amazons conditions)
                switch ($condition) {
                case "New":
                    $amazonCondition = 5;
                    break;
                case "Mint":
                    $amazonCondition = 4;
                    break;
                case "VeryGood":
                    $amazonCondition = 3;
                    break;
                case "Good":
                    $amazonCondition = 2;
                    break;
                case "Acceptable":
                    $amazonCondition = 1;
                    break;
                default:
                    $amazonCondition = 0;
                }

            //echo $condition . "|" . $ourCondition . "|" . $amazonCondition . "|" . count($lowestPrices) . "|" . $totalFeedback . "|" . $merchantId . "<br/>";

            /* default lowest 4 */
            if(count($lowestPricesDefault[$a] < 4)){ //changed to 4 per new pricing specs
                $lowestPricesDefault[$a] = str_replace('$','',$offer->Price->ListingPrice->Amount);
                $a++;
            }

            if( ($ourCondition <= $amazonCondition) && ($totalFeedback >= 99) &&  (count($lowestPrices) < 4) ) //changed to 4 per new pricing specs
            {
                $lowestPrices[$x] = str_replace('$','',$offer->Price->ListingPrice->Amount);
                $x++;
            } 
        }
        $z++;
    }



    if(count($lowestPrices) > 0){
        $avgPrice = array_sum($lowestPrices)/count($lowestPrices);
        $source = "Amazon Condition Price";
    }else{
        //$avgPrice = $listPrice - ($listPrice * 0.25);
        $avgPrice = array_sum($lowestPricesDefault)/count($lowestPricesDefault);
        $source = "Default Pricing";
    }

    //make sure avg price is atleast 5.50, >236% of follett price, and >=200% of our cost
    if($avgPrice < ($follettPrice * 2.37)){
        $avgPrice = $follettPrice * 2.37;
        $source = "Follett Pricing";
    }
    if($avgPrice < ($row['cost'] * 2)){
        $avgPrice = $row['cost'] * 2;
        $source = "Double Cost";
    }
    if($avgPrice < 5.50){
        $avgPrice = 5.50;
        $source = "Lowest Base Cost";
    }

    //update fillzPrice
    $conn->query("UPDATE inventory SET ourPrice = $avgPrice WHERE sku=" . $row['sku']);
$parsed_xml=amazon_xml($isbn);
$current=$parsed_xml->ListMatchingProductsResult->Products->Products;
$asin=$current->Identifiers->MarketplaceASIN->asin;
//根据ASIN中的项目获取信息
$price\u xml=amazonPrice\u xml($asin$ItemCondition);
$currentPrice=$price_xml->getLowstofferistingsforasinResult->Product->Lowstofferistings->Lowstofferistings;
$listPrice=$currentPrice->Price->ListingPrice->Amount;
//检查是否有值
如果(!空($listPrice))
{  
//如果($price_xml){
而(count($lowerstprices)<4)//在2012年1月5日洛拉利的电子邮件中将计数改为4
{
foreach(当前价格为$offer){
$totalFeedback=$offer->SellerFeedbackCount;
$condition=$offer->Qualifiers->ItemSubcondition;
//amazon条件匹配算法(因此我们可以将我们的条件与amazon条件进行匹配)
开关($条件){
案例“新”:
$amazonCondition=5;
打破
“铸币厂”一案:
$amazonCondition=4;
打破
“VeryGood”案:
$amazonCondition=3;
打破
案例“好”:
$amazonCondition=2;
打破
案例“可接受”:
$amazonCondition=1;
打破
违约:
$amazonCondition=0;
}
//echo$condition.“|”。$ourCondition.“|”。$amazonCondition.“|”。count($lowerstprices)。“|”。$totalFeedback.“|”。$merchantId.
”; /*默认最低4*/ 如果(count($lowerstpricesdefault[$a]<4)){//根据新的定价规范更改为4 $lowestPricesDefault[$a]=str_replace(“$”,“$offer->Price->ListingPrice->Amount); $a++; } 如果($ourCondition=99)&&(count($lowerstprices)<4))//根据新的定价规范更改为4 { $lowestPrices[$x]=str_替换(“$”,“$offer->Price->ListingPrice->Amount); $x++; } } $z++; } 如果(计数($lowerstprice)>0){ $avgPrice=array_sum($lowestprice)/count($lowestprice); $source=“亚马逊条件价格”; }否则{ //$avgPrice=$listPrice-($listPrice*0.25); $avgPrice=array_sum($lowestPricesDefault)/count($lowestPricesDefault); $source=
while(count($lowestPrices) < 4 )
{
    foreach($currentPrice as $offer)
    {
        // Do something which may add to `$lowestPrices`
        $z++;
    }
}