1 year ago
#324757
mikea
cURL error 6: Could not resolve host, after successfully resolving host
I need to update all media in a larger Shopware shop, with about 10000 products. I use the Shopware php SDK by vienthuong. I download 200 product objects at a time, create an upsert with their cover media id within a while loop.
It all goes well and good for about 2000 products. Then, nothing happens for a while, and then I get a "cURL error 6: Could not resolve host after resolving host before":
Fatal error: Uncaught GuzzleHttp\Exception\ConnectException: cURL error 6: Could not resolve host: foo-shop.de (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://glogner-shop.de/api/oauth/token in /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210
Stack trace:
#0 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(158): GuzzleHttp\Handler\CurlFactory::createRejection(Object(GuzzleHttp\Handler\EasyHandle), Array)
#1 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(110): GuzzleHttp\Handler\CurlFactory::finishError(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#2 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php(47): GuzzleHttp\Handler\CurlFactory::finish(Object(GuzzleHttp\Handler\CurlHandler), Object(GuzzleHttp\Handler\EasyHandle), Object(GuzzleHttp\Handler\CurlFactory))
#3 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php(67): GuzzleHttp\Handler\CurlHandler->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#4 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php(114): GuzzleHttp\RetryMiddleware->__invoke(Object(GuzzleHttp\Psr7\Request), Array)
#5 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php(106): GuzzleHttp\RetryMiddleware->doRetry(Object(GuzzleHttp\Psr7\Request), Array)
#6 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/RejectedPromise.php(42): GuzzleHttp\RetryMiddleware->GuzzleHttp\{closure}(Object(GuzzleHttp\Exception\ConnectException))
#7 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\RejectedPromise::GuzzleHttp\Promise\{closure}()
#8 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Promise\TaskQueue->run(true)
#9 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#10 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#11 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#12 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#13 /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\Promise\Promise->wait()
#14 /Users/m/Desktop/updater-dev/coverImage/vendor/vin-sw/shopware-sdk/src/Client/Client.php(108): GuzzleHttp\Client->request('POST', 'https://glogner...', Array)
#15 /Users/m/Desktop/updater-dev/coverImage/vendor/vin-sw/shopware-sdk/src/Client/Client.php(135): Vin\ShopwareSdk\Client\Client->request('POST', 'https://glogner...', Array)
#16 /Users/m/Desktop/updater-dev/coverImage/vendor/vin-sw/shopware-sdk/src/Client/AdminAuthenticator.php(56): Vin\ShopwareSdk\Client\Client->post('https://glogner...', Array)
#17 /Users/m/Desktop/updater-dev/coverImage/token.php(15): Vin\ShopwareSdk\Client\AdminAuthenticator->fetchAccessToken()
#18 /Users/m/Desktop/updater-dev/coverImage/main.php(61): require('/Users/miamahnc...')
#19 {main}
thrown in /Users/m/Desktop/updater-dev/coverImage/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 210
So, the error is telling me that it can't get the auth token, which worked fine before.
Code:
$time_pre = microtime(true);
require __DIR__ . '/token.php';
$criteria = new Criteria(1, 200);
$criteria->setTotalCountMode(1);
$criteria->addInclude('product', ["coverId"]);
$page_count = 1;
$total_product_count = 0;
do{
$context = new Context($config['shop_url'], $accessToken);
$syncService = new SyncService($context);
$data = [];
$payload = new SyncPayload();
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
$products = $productRepository->search($criteria, $context); //EntitySearchResult
$criteria->setPage($page_count);
if(microtime(true) >= $time_pre+(10*50) ){
echo "getting new token! \n";
$time_pre = microtime(true);
require __DIR__ . '/token.php';
$context = new Context($config['shop_url'], $accessToken);
$syncService = new SyncService($context);
}
$total_product_count += $products->count();
foreach( $products->getEntities()->getElements() as $key => $entity){
$ci = $entity->coverId;
if(!is_null($ci)){
$data[] = array('id' => $ci, 'position' => 0);
}
}
$payload->set(ProductMediaDefinition::ENTITY_NAME . '-upsert', new SyncOperator(ProductMediaDefinition::ENTITY_NAME, SyncOperator::UPSERT_OPERATOR,
$data
));
if(microtime(true) >= $time_pre+(10*50) ){
echo "getting new token! \n";
$time_pre = microtime(true);
require __DIR__ . '/token.php';
$context = new Context($config['shop_url'], $accessToken);
$syncService = new SyncService($context);
}
$response = $syncService->sync($payload);
++$page_count;
}while($products->getMeta()->getTotal() - $total_product_count > 0);
It's not that pretty anymore, but I just want it to work first.
php
guzzle
shopware6
0 Answers
Your Answer