title: Inconsistent Curl response from localhost to live site
body: <p>Hi everyone I have a php file which returns a JSON which I constructed from a response from curl. My Problem is when I run it in locally(localhost) server the JSON response its length is 55 which is correct, it got all the events I needed. But when I tried it on our hosting site, the response is inconsistent, it is different from the localhost. For the first load I checked the length response and it returns 32 events out of 55, then I tried to reload it again then the response increased to 39 etc.. </p>
  
  <p>This is my localhost response. [<a href="https://prnt.sc/rll4w0]" rel="nofollow noreferrer">https://prnt.sc/rll4w0]</a>. This the file hosted on cpanel <a href="https://cdev.trilogycap.co/icedev/dynamic/civicore.php" rel="nofollow noreferrer">https://cdev.trilogycap.co/icedev/dynamic/civicore.php</a> .This is the first response <a href="https://prnt.sc/rll2rc" rel="nofollow noreferrer">https://prnt.sc/rll2rc</a> .And when I reload this page again <a href="https://prnt.sc/rll3fl" rel="nofollow noreferrer">https://prnt.sc/rll3fl</a></p>
  
  <p>My php file function process is like this.
  I have a function which gets all the ID's of the event of this year and push it to the global array. I have removed the duplicate ID's there. So now I call a function for multicurl. </p>
  
  <p>In which, for each ID I will process and call the API again and construct it. I then pushed it to my responseEvents variable array in global which then I encode to be able to make a valid JSON file. Is there a connection or wrong thing I did in my multi curl? Is their an execution limit to php multi curl? Or is the settimelimit(0) affect my code?</p>
  
  <p>Here's my code</p>
  
  <pre><code>&lt;?php
  //Use this so that when we run the curl it wont timeout when dealing with getting data
  set_time_limit(0);
  $API_KEY  = "APIKEY";
  $CURRENT_YEAR = date("Y");
  $CURRENT_MONTH = date("m");
  $CURRENT_DAY = date("d");
  $events = getOpportunityYearly();//array of ID's removed duplicates [1,1,2,3,4,5 etc]
  $noDuplicate =  array_values(array_unique($events));//remove $event ID duplciates
  $responseEvents = [];//this is the array to be returned as json to use
  
  //pass noDuplicate array which holds event ID's
  multiCurl($noDuplicate);
  print_r(json_encode($responseEvents, JSON_HEX_QUOT |  JSON_HEX_TAG | JSON_HEX_AMP |JSON_UNESCAPED_SLASHES ));
  
  //returns an array of ID of events
  function getOpportunityYearly(){
    $eventArr = [];//pass eventsID here
    $curl = curl_init();
  
    curl_setopt_array($curl, array(
        CURLOPT_URL =&gt; 'https://api.com/voc/api/v3/data/opportunities_dates?key='.$GLOBALS['API_KEY'].'&amp;fields=["startDate","endDate","opportunities_id"]&amp;where={"whereType":"AND","clauses":[{"fieldName":"startDate","operator":"&gt;=","operand":"'.$GLOBALS['CURRENT_YEAR'].'-'.$GLOBALS['CURRENT_MONTH'].'-'.$GLOBALS['CURRENT_DAY'].'"},{"fieldName":"endDate","operator":"&lt;=","operand":"'.$GLOBALS['CURRENT_YEAR'].'-12-31"}]}',
        CURLOPT_RETURNTRANSFER =&gt; true,
        CURLOPT_ENCODING =&gt; "",
        CURLOPT_MAXREDIRS =&gt; 10,
        CURLOPT_TIMEOUT =&gt; 0,
        CURLOPT_FOLLOWLOCATION =&gt; true,
        CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST =&gt; "GET",
    ));
  
    //convert response to obj
    $response = json_decode(curl_exec($curl));
    curl_close($curl);
    $eventsID = $response-&gt;records;
    //print_r($eventsID);
  
    //every opportunity object get its id and push to events array
    foreach($eventsID as $opportunity){
      array_push($eventArr,$opportunity-&gt;opportunities_id-&gt;value);
    }
    return $eventArr;
  }
  
  function multiCurl($eventArray){
      // array of curl handles
      $multiCurl = array();
  
      // data to be returned
      $result = array();
  
      // multi handle
      $mh = curl_multi_init();
      $index = null;
  
      foreach ($eventArray as $event) {
          //$event are the ID per each event
          $multiCurl[$event] = curl_init();
          curl_setopt_array($multiCurl[$event], array(
            CURLOPT_URL =&gt;'https://api.com/voc/api/v3/data/opportunities/'.$event.'?key='.$GLOBALS['API_KEY'].'&amp;fields=["opportunityName","typeOfWork","firstDateInOpportunity","lastDateInOpportunity","startTime","endTime","physicalDifficulty","minimumAge","location","state","city","county","campingAvailable","groupsAllowed","registrationFormID","cRQ_payment","paymentAmount","additionalInformation","photo","displayToPublic","latitude","longitude","summary","description","photo"]&amp;where={"whereType":"AND","clauses":[{"fieldName":"displayToPublic","operator":"checked"}]}',
            CURLOPT_RETURNTRANSFER =&gt; true,
            CURLOPT_ENCODING =&gt; "",
            CURLOPT_MAXREDIRS =&gt; 10,
            CURLOPT_TIMEOUT =&gt; 0,
            CURLOPT_FOLLOWLOCATION =&gt; true,
            CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST =&gt; "GET"
          ));
          curl_multi_add_handle($mh, $multiCurl[$event]);
      }
  
      do {
        curl_multi_exec($mh,$index);
      } while($index &gt; 0);
  
        // get content and remove handles
        foreach($multiCurl as $key=&gt;$value) {
  
          $records = json_decode(curl_multi_getcontent($value));//response of each request
          $record  = $records-&gt;records[0];
  
         if(strtolower($record-&gt;displayToPublic-&gt;displayValue) == 'yes'){
            $eve =  [ 
              "page_item_url"=&gt; $record-&gt;opportunities_id-&gt;value,
                "data"=&gt;[
                  "typeOfWork"=&gt;$record-&gt;typeOfWork-&gt;displayValue,
                  "opportunityName"=&gt; $record-&gt;opportunityName-&gt;displayValue,
                  "firstDateInOpportunity"=&gt; $record-&gt;firstDateInOpportunity-&gt;displayValue,
                  "lastDateInOpportunity"=&gt; property_exists($record, 'lastDateInOpportunity') ? $record-&gt;lastDateInOpportunity-&gt;displayValue : $record-&gt;firstDateInOpportunity-&gt;displayValue,
                  "startTime"=&gt;$record-&gt;startTime-&gt;displayValue,
                  "endTime"=&gt;$record-&gt;endTime-&gt;displayValue,
                  "physicalDifficulty"=&gt;$record-&gt;physicalDifficulty-&gt;displayValue,
                  "minimumAge"=&gt;$record-&gt;minimumAge-&gt;displayValue,
                  "location"=&gt;$record-&gt;location-&gt;displayValue,
                  "state"=&gt;$record-&gt;state-&gt;displayValue,
                  "city"=&gt;$record-&gt;city-&gt;displayValue,
                  "county"=&gt;$record-&gt;county-&gt;displayValue,
                  "campingAvailable"=&gt;$record-&gt;campingAvailable-&gt;displayValue,
                  "groupsAllowed"=&gt;$record-&gt;groupsAllowed-&gt;displayValue,
                  "registrationFormID"=&gt;$record-&gt;registrationFormID-&gt;displayValue,
                  "cRQ_payment"=&gt;$record-&gt;cRQ_payment-&gt;displayValue,
                  "paymentAmount"=&gt;$record-&gt;paymentAmount-&gt;displayValue,
                  "photo"=&gt;$record-&gt;photo-&gt;displayValue,
                  "displayToPublic"=&gt;$record-&gt;displayToPublic-&gt;displayValue,
                  "latitude"=&gt; property_exists($record, 'latitude') ? $record-&gt;latitude-&gt;displayValue : "0",
                  "longitude"=&gt; property_exists($record, 'longitude') ? $record-&gt;longitude-&gt;displayValue : "0",
                  "photo"=&gt;$record-&gt;photo-&gt;displayValue,
                  "description"=&gt; $record-&gt;description-&gt;displayValue,
                  "additionalInformation"=&gt; $record-&gt;additionalInformation-&gt;displayValue,
                  "summary"=&gt; $record-&gt;summary-&gt;displayValue
                  ]
                ];
                array_push($GLOBALS["responseEvents"],$eve);
                curl_multi_remove_handle($mh, $value);
          }
        }//foreach
      curl_multi_close($mh);
  }
  
  ?&gt;
  
  
  </code></pre>