0

I am using curl multi exec in php. I read some urls from db and pass on to curl. These urls also have ids associated to it. When download is completed it is important to know the id associated to it. Could you please tell me is there anyway to pass a variable and curl will return it in the response.

Thanks in advance wantro

2 Answers 2

3

You could just maintain your own data associations for every curl handle.

$associatedData = array();

$ch = curl_init();
$id = (int) $ch; // will yield a unique number because resources have a globally unique numeric id
$associatedData[$id] = array('data' => $foo);

// now add it via curl_multi_add_handle() etc...

Then, later when you're processing the handles, you can lookup the associated data

$id = (int) $ch; 
$data = $associatedData[$id];
Sign up to request clarification or add additional context in comments.

Comments

2

Store private data inside the cURL easy handle, e.g.:

curl_setopt($ch, CURLOPT_PRIVATE, $url->getId());
// then later
$id = curl_getinfo($ch, CURLINFO_PRIVATE);

This "private data" feature is not (yet) documented in the PHP manual. It was introduced already in PHP 5.2.4. It allows you to store and retrieve a string of your choice inside the cURL handle. Use it for URL IDs.

See duplicate question php - CURL Multi get info about a particular handle.

Comments

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.