connect to multiple sites with cURL

0

If there was a list of 10 sites, or more, using cURL to connect to and puta content of each site, what would be the most effective way, which would give less time between one connection and another. That is, what good practice for this case, something like:

Starting cURL - > set options- > close, and start again for the next site, .. Note: the options, as they are the same for all the sites that I'm going to connect, can create an array and use curl_setopt_array , not to get a giant code.

Opening and closing the connection for each site, assuming that the cURL options would be the same, the only difference would be curlopt_url ..?

    
asked by anonymous 12.01.2015 / 14:08

1 answer

1

At times as soon as I miss threads in PHP ...: (

Considering that only the URL will be changed for each request, you can use the following logic:

$ch = curl_init();

// todos os curl_setopt aqui, exceto a URL

foreach ( $urls as $url )
{
    curl_setopt( $ch, CURLOPT_URL, $url );

    curl_exec( $ch );
}

curl_close( $ch );

More about cURL here: link

    
12.01.2015 / 14:41