I'm trying to create a system, but I have a question, I wanted to send the request all at once through curl_init, I want to send it to fetch 3 servers at a time.
I'm trying to create a system, but I have a question, I wanted to send the request all at once through curl_init, I want to send it to fetch 3 servers at a time.
If you have to get 3 servers then there will be 3 requests, but one way is to create a function that takes care of all of them:
function get_data($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, True);
curl_setopt($curl, CURLOPT_URL, $url);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
$urls = array('url1', 'url2', 'url3'); // só tem de adicionar/retirar os serviços daqui
$datas = array();
for($i=0; $i<count($urls); $i++) {
$datas['url_' .$i] = get_data($urls[$i]);
}
// ex: $datas['url_0'] = conteudos do primeiro serviço a que acedeu ('url1')
Well this was my code, I'm new to PHP
$ch = curl_init('http://meusite.com.br/servidor1.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "id=$id");
$teste = curl_exec ($ch);
curl_close ($ch);