curl multi exec get index

Solutions on MaxInterview for curl multi exec get index by the best coders in the world

showing results for - "curl multi exec get index"
Giuseppe
25 Oct 2017
1$nodes = array('http://www.google.com', 'http://www.microsoft.com', 'http://www.rustyrazorblade.com');
2$node_count = count($nodes);
3
4$curl_arr = array();
5$master = curl_multi_init();
6
7for($i = 0; $i < $node_count; $i++)
8{
9    $url =$nodes[$i];
10    $curl_arr[$i] = curl_init($url);
11    curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
12    curl_multi_add_handle($master, $curl_arr[$i]);
13}
14
15do {
16    curl_multi_exec($master,$running);
17} while($running > 0);
18
19echo "results: ";
20for($i = 0; $i < $node_count; $i++)
21{
22    $results = curl_multi_getcontent  ( $curl_arr[$i]  );
23    echo( $i . "\n" . $results . "\n");
24}
25echo 'done';
Zachariah
16 Nov 2018
1/*when using curl multi exec you may need to pass some data about the request
2and retrieve that data whenever the request is done processing you can
3use curl's private data feature like so to achieve this:*/
4curl_setopt($curl_handle, CURLOPT_PRIVATE, $someIndex);
5
6//.... then later
7$info = curl_multi_info_read($handle);//read the info
8$someIndex = curl_getinfo($info['handle'], CURLINFO_PRIVATE);