Skip to content

Instantly share code, notes, and snippets.

@ManishLSN
Created May 2, 2018 10:52
Show Gist options
  • Save ManishLSN/db3977a92ba2b7dfaa83a15bd569ccdc to your computer and use it in GitHub Desktop.
Save ManishLSN/db3977a92ba2b7dfaa83a15bd569ccdc to your computer and use it in GitHub Desktop.
call multiple curl with one script.
<?php
$url1 = 'https://api.giphy.com/v1/gifs/search?limit=15&q=he&api_key=xTiQyliBbaDfjlTkC4&rating=pg-13';
$url2 = 'https://api.iextrading.com/1.0/stock/MSFT/quote';
$url3 = 'https://api.iextrading.com/1.0/stock/GOOGL/quote';
$nodes = array($url1, $url2, $url3);
$node_count = count($nodes);
$curl_arr = array();
$master = curl_multi_init();
for($i = 0; $i < $node_count; $i++)
{
$url =$nodes[$i];
$curl_arr[$i] = curl_init($url);
curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
curl_multi_add_handle($master, $curl_arr[$i]);
}
do {
curl_multi_exec($master,$running);
} while($running > 0);
for($i = 0; $i < $node_count; $i++)
{
$results[] = curl_multi_getcontent ( $curl_arr[$i] );
}
print_r($results);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment