PHP, Curl, curl_exec (), curl_close () and cookies

When using PHP with Curl, do you need to call curl_close () after each call to curl_exec () for cookies to work correctly using the CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE parameters? Or can I call curl_exec () as many times as I like in different URLs on the same site, and cookies are still saved without calling curl_close () after each of them? Is it possible to use curl_exec () many times and just close curl_close () at the end of the script?

+5
source share
1 answer

You should only call curl_close()when you know that you are done with this particular descriptor, or if the transition from the current state to the new one (i.e. changing a ton of options with the help curl_setopt()will be faster, going from a clean new handle than your current "dirty" one.

The cookiejar / file parameters are strictly necessary to support cookies between individual / invokations handles. Each of them is independent of the others, therefore cookies are the only way to exchange between them.

+2
source

All Articles