I am using Guzzle 6 to update products to shopify via API. I am using async post method to upload products in bulk, but in response if any error occur in any posted requests , I am unable to find out which requests cause this error. As response come only after completion of async function. Any solution to this ? How can we find out postAsync requests cause error , so that we can store status of failed and success requests individually ? Also, post request limit is 2calls per second as per shopify.
I am using this code:
$client = new Client();
$url = "https://optimze-test.myshopify.com/admin/api/2019-07/products.json";
$promises = (function () use ($main_array,$client,$ShopifyHeaders,$url) {
foreach ($main_array as $project) {
// don't forget using generator
yield $client->postAsync($url,['json' => $project,'headers'=>$ShopifyHeaders]);
}
})();
$eachPromise = new EachPromise($promises, [
// how many concurrency we are use
'concurrency' => 10,
'fulfilled' => function (Response $response) {
if ($response->getStatusCode() == 200) {
$data = json_decode($response->getBody(), true);
// processing response of user here
echo "successes";
Log::info('success::'.$data);
}
},
'rejected' => function ($reason) {
// handle promise rejected here
echo "fail";
Log::info('fail::'.$reason);
}
]);
$eachPromise->promise()->wait();
Where $main_array is array of data of products to be posted .
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community