I'm getting this annoying error 429 for too many requests while sending multiple requests. What's even more disgusting is it limits amount of product to 10 per request as it seems.
So I have a code that breaks down my asin array into groups of 10s and chains it into multiple requests however, when I set 1 second wait after start of every request before making a new one, it doesn't work reliably and still returns an error, increasing the number to 2 sec per request solves this but makes it too slow. (Because usually it takes 0.5 sec per request and waits the remaining 1.5 seconds).
Amazon doesn't have any documentation on how exactly those limits work so we can only guess.
Is there way to improve it further or make something different with the queuing?
$all_posts = get_posts(array(
'posts_per_page' => -1
));
$serialized = serialize($all_posts);
preg_match_all ( "/]([^\]]*?)\[\/asa\]/" , $serialized , $matches);
$amazon_items=$matches[1]; //here we get an array of asins
$time_end=microtime(true);
$time_start=0;
$out=array();
for ($i=0;$i<count($amazon_items);$i+=10){
$arr=array();
for ($j=0;$j<10&&$i+$j<count($amazon_items);$j++){
$arr[]=$amazon_items[$i+$j];
}
if ($time_end-$time_start<2) {
echo 'sleeping '.(2-($time_end-$time_start)). 'sec; ';
sleep (2-($time_end-$time_start));
}
$time_start = microtime(true);
$list = GetItems($arr);
$time_end = microtime(true);
echo $time_end-$time_start.' sec, ',PHP_EOL;
$out = array_merge($out, $list);
}