Posts

Showing posts with the label libcares

Curl multi hangs, connection timeout. Asynchronous DNS support

The problem. Curl is a nice library that takes advantage of asynchronous loading. Many developers use CURL in high level languages to load multiple web pages simultaneously. I use curl_multi functions very heavily in my PHP scripts too. But recently i discovered very awkward problem: CURL loads web pages asynchronously but DNS resolution is single threaded! This means that if one of the CURL handles hangs on DNS resolving other handles will hang too and wait for their turn in resolving queue! And if you set curl option "connection timeout" and DNS resolving takes more than timeout you set - all requests will fail! The solution. Starting from version 7.20.0 CURL can handle async DNS resolution using libcares. But cares support isn't enabled by default (at least in Opensuse packages and FreeBSD ports). To take advantage of async DNS resolution rebuild libcurl with --enable-ares option. If your copy of the libcurl is already compiled with async DNS support PHP will repor