connect to multiple sites with Curl

Asked

Viewed 529 times

0

If there was a list of 10 sites, or more, using Curl to connect and puck content from each site, which 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:

Start Curl -> set options-> close, and start again for the next site,. Obs: the options, as they are the same for all the sites I will connect, I can create an array and use the curl_setopt_array, not to be a giant code.

opening and closing connection to each site, considering that the Curl options would be the same, the only different would be the curlopt_url..?

1 answer

1

At times like this I miss threads in PHP... :(

Whereas only the URL will be changed with 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: http://rberaldo.com.br/trabalhando-com-a-biblioteca-curl/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.