I am not sure how can or if I can use php multi curl function in the following situation:
I need to curl 3 different links while all of them are dependent to each other. With the unique id obtained from the first link I will access the second link to retrieve another unique id which will be used in the 3rd link for the final result. See example below for better understanding:
$agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36";
//open the session with the first link
$url1 = "http://first-link-example.com/execute";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
$results = curl_exec($ch);
//get unique id from the link above
$unique1 = explode("string1", $results);
$unique1 = explode("string2", $unique1[1]);
//new request to access second link while preserving the session
$url2 = "http://second-link-example.com/execute?id=".$unique1[0];
curl_setopt($ch, CURLOPT_URL, $url2);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
$results2 = curl_exec($ch);
//get the second unique id from $results2 page
$unique2 = explode("string1", $results2);
$unique2 = explode("string2", $unique2[1]);
//final request to retrieve the desired string while preserving the session
$url3 = "http://third-link-example.com/execute?id=".$unique2[0]."/response";
curl_setopt($ch, CURLOPT_URL, $url3);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
$results3 = curl_exec($ch);
//get the desired string from $results3 page
$success = explode("string1", $results3);
$success = explode("string2", $success[1]);
echo $success[0];
curl_close($ch);
I did a lot of research on the web but couldn't find something appropriate and I wasn't able to understand how can I use multi curl in my situation or if it's possible.
Hopefully I made myself clear enough regarding what I'm looking for.
Thanks in advance to anyone who will be able to help me.