difference between executing curl_close() once or frequently?

Viewed 7739

When is it necessary to close curl connection and release resources consumed by it?

Why do I ask this question, well quite simply because I was told, that PHP garbage collector does all of this and sometimes there is no need to close DB connection or call the __destruct method to release resources.

Since, that moment I actually started to think about where do I need to call it then? At the moment I'm interested with that question since I writing a small library for curl and I'd like to understand when do I need to user curl_close() function.

Thank you all for discussion and explanation of it.

3 Answers

Depends. In my case since I was initializing curl instance in my custom CurlClient constructor

$this->ch = curl_init();

And then using same $curlClient object for multiple api calls, closing the instance

curl_close($this->ch);

would affect other API calls. Methods using the same object will not work, so I'm not closing it.

Related