Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is PHP-CURL's curl_multi_exec really multithreaded internally?

My question is very simple as stated in title. However I rephrase it again.

I want to download multiple sites using php-curl. I'll run it from console. I am going to use curl_multi_exec to download all the sites. Now the question, will curl create different threads for each of the request?

I know I can achieve it by forking multiple processes. But thats not threading. I dont want threading. I want to know if its multi-threaded?

like image 974
Shiplu Mokaddim Avatar asked Jan 16 '12 15:01

Shiplu Mokaddim


1 Answers

No. The libcurl multi interface (that PHP uses under the hood to do this job) does multiple requests in parallel, but it does so using non-blocking API calls. Not threads.

In the past

(This section can now be considered historic since libcurl builds with the threaded resolver by default since years back now.)

The problem that people might face then occurs when a specific transfer needs to resolve a host name as the standard host name resolver functions in most operating systems are synchronous which makes each resolve block all the other transfers. This is overcome in libcurl by providing alternative resolver backends such as one built to use c-ares for resolving and another that fires up the "stock resolver" in a separate thread - the so called threader resolver.

like image 157
Daniel Stenberg Avatar answered Sep 20 '22 18:09

Daniel Stenberg