Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8436389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:09:59+00:00 2026-06-10T07:09:59+00:00

I am running two almost identical programs with the exception that one needs to

  • 0

I am running two almost identical programs with the exception that one needs to only look at the lowest price, the second needs to look at the lowest 4 prices and get the average. my problem is that when running the second program, I get an out of memory php fatal error. My hosting provider has set the memory limit to 3000M for me and I still get the error.
Here is the code for the first program:

    $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']);

Here is the second program:

    $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']);

I have been getting the error on line 86 of the second program which is the condition line ($condition = $offer->Qualifiers->ItemSubcondition;) Does anyone have an idea why this is happening? Also, does anyone have any suggestions to make it run any better?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:10:00+00:00Added an answer on June 10, 2026 at 7:10 am

    First, two code-review points:

    1. You have variables $a, $x, and $z, all with no initial condition, and all entirely opaque to anyone trying to maintain the code. A single $i as a loop-counter is commonly considered acceptable, but good variable-naming can make debugging a lot easier.
    2. When using SimpleXML, always cast values to a string: $asin = $current->Identifiers->MarketplaceASIN->ASIN; should read $asin = (string)$current->Identifiers->MarketplaceASIN->ASIN; Among other things, forgetting to do this will mean that $asin could never be saved to a session (since SimpleXML objects cannot be serialized).

    As for why your code is failing, I think the structure of your loops is wrong:

    while(count($lowestPrices) < 4 )
    {
        foreach($currentPrice as $offer)
        {
            // Do something which may add to `$lowestPrices`
            $z++;
        }
    }
    

    Firstly, $z doesn’t seem to be used for anything. Secondly, $lowestPrices may be added to 0, 1, 4, or even 100 times inside the foreach loop. If it is added to at least 4 times, the while loop will immediately exit (so might as well not exist); if it is added to less than 4 times, the foreach loop will simply be run again over the same data. It’s not clear to me that this will make it any more likely to meet the condition of the while loop, giving you an infinite loop.

    The reason you’re running out of memory, rather than just CPU time, is the additional array $lowestPricesDefault grows even when $lowestPrices doesn’t, so it will carry on growing indefinitely every time the while loop (and therefore the whole inner foreach loop) repeats.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I run the very same query on two almost identical database. The only difference
I have a single Magento install running two different websites. One sells ebooks and
I have project in Dropbox and two running laptops: one with Ubuntu and one
I am developing a web app that will have two parts running on two
I've two for loops that basically look up in two different arrays (each having
Is there a way to merge two exe files into one, programmatically, so that
I am running two queries to my database for pagination reasons. As such, each
Here I am running two instance of same program in two different terminals. The
I have two different web applications running on two different instances of tomcat. I
I'm running into two issues with Derby and Mongo. I come from a MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.