L
L
LNK2018-08-21 11:16:11
PHP
LNK, 2018-08-21 11:16:11

Why are curl requests hanging?

I have a server on Ubuntu and a php application that makes requests to vk api via https via curl. The vk api itself can hardly hang, because on the https://vk.com/dev/health page , the execution time of any methods is measured in milliseconds. But quite often (albeit without any regularity) my curl requests start to freeze and break on timeout (5 seconds).
These are the errors returned by curl:
Resolving timed out after 2527 milliseconds
I send requests with the following options:

curl_setopt($ch, CURLOPT_URL, 'https://api.vk.com/method/<имя метода, которому обращаюсь>');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['param1'=>$value, ...])); // параметры для vk api
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );

I added the last line after reading the article on Habré , but it did not help.
I don't know what to think anymore. Maybe I have some problems with the certificates?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2018-08-21
@ky0

It looks like you don't use caching of DNS responses and the DNS server is periodically dumb.

M
Melkij, 2018-08-21
@melkij

This error (the only place with such a wording of the text, does not occur in the PHP source, only proxied from libcurl) arrives when the timeout is reached, when the connection is in the CURLM_STATE_WAITRESOLVE status - that is, still waiting for a DNS response.
Check the DNS used by the system

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question