0

I'm developing a script in which I use "curl_multi" to handle some requests to APIs faster (?).

Although I have read both by looking on google (maybe I search badly) and in the documentation of the PHP site, I cannot understand if the command: "curl_multi_close" actually closes all the various "curls" contained within it or not.

Since this is not clearly explained in the documentation, since in the example it removes (and subsequently closes individually) the curls one by one, but reports as a description of the command: "Closes a set of cURL handles.".

-- EDIT --

My requests are independents by each other's

Giuseppe
  • 531
  • 1
  • 5
  • 19
  • Why do you think it will be faster? – Dharman Mar 02 '20 at 21:07
  • Another question response here on StackOverflow says "Use curl_multi_init to run the processes in parallel.." So I supposed that is faster than open and close 5/6 curl instances, Am I wrong? – Giuseppe Mar 02 '20 at 21:13
  • I am afraid you are misunderstanding the purpose of this function. I recommend you play around with it and see for yourself how it behaves. You need to also understand how a blocking loop works and what is the advantage of doing it. It might be faster, but that depends on what you want to optimize. If you are optimizing prematurely then you are definitely going to miss your goals. – Dharman Mar 02 '20 at 21:16
  • If you need to do several independent curl requests, using `curl_multi` to fire them all off in parallel will be faster than doing one after the other in series. Your question doesn't explicitly state you want to do multiple requests, so it isn't explicitly clear why you think it would be faster, maybe that explains the other comments here. – Don't Panic Mar 02 '20 at 21:20
  • I'm sorry, yes, my requests are indipendents to each other's. Sorry, returning to the question, "curl_multi_close" close all instances or do I have to close them manually? – Giuseppe Mar 02 '20 at 21:21
  • As to your question, [the PHP docs give a pretty good example](https://www.php.net/manual/en/function.curl-multi-close.php) - `curl_multi_close()` closes the main handle returned by `curl_multi_init()`. – Don't Panic Mar 02 '20 at 21:24
  • It says "Closes a SET of cURL handles.", so I have not to interpretate that as "set"->"""list"""(?) – Giuseppe Mar 02 '20 at 21:25
  • 1
    Agreed the terminology might be confusing, but the simple example there shows exactly what it does and how to use it. – Don't Panic Mar 02 '20 at 21:28

0 Answers0