• Hi,

    I use your plugin to find price of product (with ASIN) on Amazon, and stock their price in a custom field of my WP product.

    I use a CRON Job which execute my code each night. This code call your shortcode for all my products (one per one) and stock the return price in my WP custom field.

    But, the result is random. Somes prices are good and many other are empty.

    In my opinion, your plugin does’nt support the fact that many requests for all my products (about 30) are send in the same time.

    What about you ? Do you have a solution ?

    Would it be a good idea to put a “break” (in the code) after each call to Amazon and continu to execut ? How can I do this ?

    Thanks for your answer, and sorry for my poor english !

    Best regards

    if($v1_asin != ''){
    	$short_ama_price = ('asin='.$v1_asin.'&template=price');
    	if (function_exists(amazon_shortcode)) {
    		$api_price_ama = amazon_shortcode($short_ama_price);
    		if($api_price_ama == '-') {
    			$api_price_ama = '';
    		}
    		else {
    			$api_price_ama = str_replace('EUR ','',$api_price_ama);
    		}
    	}
    	$short_ama_url = ('asin='.$v1_asin.'&template=url');
    	if (function_exists(amazon_shortcode)) {
    		$api_url_ama = amazon_shortcode($short_ama_url);
    	}
    	update_field('v1_amazon_price', $api_price_ama, $post_id);
    	update_field('v1_amazon_url', $api_url_ama, $post_id);
    }

    https://ww.wp.xz.cn/plugins/amazon-link/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author paulstuttard

    (@paulstuttard)

    Hi,

    The AWS does not allow more than a few requests per second, so you may need to slow it down. The plugin normally manages this by using the cache, but obvious you want live prices.

    If you only need to get a few product prices, you could slow the script down, add the line:

    // Sleep for 200,000us to slow down requests
    usleep(200000);

    So for your 30 products it should take about 6 seconds to retrieve all the prices.

    Hope this helps,

    Paul

    Thread Starter SkuD4012

    (@skud4012)

    Hi,

    Thanks Paul !

    Your solution is good but 0,2 second is again too short, many price product are always empty (random product).
    After search on Amazon API Doc, I see that Amazon accept just one request per second.

    So I define : usleep(1000000);
    And it’s OK, all prices are good.

    But in the future, I’ll continu to add other products … and one day I’ll will have an error because I exceed the max_execution_time imposed by my hoster.

    If you have a permanent solution I’m listening ? 😉

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Bug when too many requests’ is closed to new replies.