AnsweredAssumed Answered

Process multiple cURL with PHP

Question asked by on Feb 8, 2016
Latest reply on Jul 13, 2018 by James Jones



I'm new to programming, but made a page using PHP that lets us enter userIDs and add observers using the Canvas API and that worked great. I'm now trying to enter a list of people to be observed and have it process multiple URLs and that is where I'm running into problems. It only seems to process the final userID in the box. Any ideas what I'm doing wrong? This doesn't need to be run often and I'm not worried about performance so I don't really need the cURL commands to process simultaneously.


$observeeA = explode ("\n", $observee);
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 foreach ($observeeA as $ob2){
   if ($idtype == "Canvas") {
     $url = $domain . "/api/v1/users/$observer/observees/" . $ob2; }
   else {
     $url = $domain . "/api/v1/users/sis_user_id:$observer/observees/sis_user_id:" . $ob2; }
   curl_setopt($ch, CURLOPT_URL, $url);
   $resp = curl_exec($ch);
   echo $ob2 . "<br>" . $url . "<br>" . $resp . "<br>";


The echo on line 13 outputs all the correct entries for the URL, but it never gets a response until the last one in the list.