6

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?

3
  • While this is a question that can simply be answered by looking into the source of cURL, the underlying question can be more interesting: why do you want to know this? Specify more information on why you are thinking that multicURL does not use threads. Commented Jan 16, 2012 at 16:04
  • I was in fact trying to download files simultaneously. But PHP is not multi-threaded. So I thought try curl_multi_*. Then this question came into my mind. Commented Jan 16, 2012 at 16:11
  • 1
    a PHP script being executed might happen on one thread, that doesn't say anything about libraries (like cURL) you call. Any external call you perform might start one or more new threads. Commented Jan 16, 2012 at 16:15

1 Answer 1

13

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Yes, we know that on the PHP end, there is a single thread. What about cURL internally? I think that is the question here. Ignore the name resolving issue for the moment.
I am talking about libcurl internally. I don't know the PHP stuff, but I know the libcurl internals very well...
@Brad I dont think anyone other than the author himself can answer better.
Presumably curl multi is faster / uses less resources / ram then for not using threads? I assume the operating system doesn't run threads on its side of things and has a faster way to go about everything.
Primarily it is much less resource intensive. A normal thread on Linux takes at least 8MB of stack space. 100 threads means 800 MB of ram just "wasted" on stacks alone...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.