GenuinePlaceholder
GenuinePlaceholder

Reputation: 695

Reset / Reuse / Clone cURL Multi Handle

I have a specific problem which requires me to reuse cURL multi handles. Is there a way to do that? I tried to use

curl_copy_handle()

And it did not work saying

 curl_copy_handle(): supplied resource is not a valid cURL handle resource

Which is not totally unexpected. Is there a way to reuse or clone a cURL multi handle?

Edit: Calling

clone

Also does not work

Fatal error:  __clone method called on non-object

Upvotes: 0

Views: 753

Answers (1)

François
François

Reputation: 1852

I don't think this is possible with a single built-in function.

As you creating the original cURL multi handle, right before each curl_multi_add_handle() call, save a copy of each easy (regular) handle in an array A with curl_copy_handle().

Then, when you need to re-use the multi handle:

  • Create a new empty one with curl_multi_init()
  • Loop through each element of A
  • In the loop, use curl_multi_add_handle() to add a copy (again, with curl_copy_handle()) of each easy handle to the new multi handle

Upvotes: 1

Related Questions