specifying multiple URLs with cURL/PHP using square brackets
- by Raj Gundu
I have a large array of URLS similar to this:
$nodes = array(
'http://www.example.com/product.php?page=1&sortOn=sellprice',
'http://www.example.com/product.php?page=2&sortOn=sellprice',
'http://www.example.com/product.php?page=3&sortOn=sellprice'
);
The cURL manual states here (http://curl.haxx.se/docs/manpage.html) that i can use square brackets '[]' to specify multiple urls. Used in the above example this would be similar to this:
'http://www.example.com/product.php?page=[1-3]&sortOn=sellprice'
So far i have been unable to reference this correctly. This is the complete code segment I'm currently trying to utilize this with:
$nodes = array(
'http://www.example.com/product.php?page=1&sortOn=sellprice',
'http://www.example.com/product.php?page=2&sortOn=sellprice',
'http://www.example.com/product.php?page=3&sortOn=sellprice'
);
$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);
echo "results: ";
for($i = 0; $i < $node_count; $i++)
{
$results = curl_multi_getcontent ( $curl_arr[$i] );
echo( $i . "\n" . $results . "\n");
echo 'done';
I can't seem to find any more documentation on this. Thanks in advance.