处理反向地理编码响应

I have got one reverse geocoding script which returns a city name on the basis of latitude & longitude.It works fine whenever we tried to see the result only for one city. But when I run the same script in foreach loop (approx 3000 city one by one) it will take a time but returns a blank response due to which my dependant code gives wrong result.

Have written the below code, which works fine for near about first 30 records then it gives blank response again after 20 odd records it gives proper result & so on. Because of which I need to execute this script for every 30 records & my total records are near about 30K.

foreach ($cityArray as $city)
{
    $curl = curl_init('https://us1.locationiq.com/v1/reverse.php?key=MY_KEY&lat=CITY_LATITUDE&lon=CITY_LONGITUDE&format=json');

    curl_setopt_array($curl, array(
      CURLOPT_RETURNTRANSFER    =>  true,
      CURLOPT_FOLLOWLOCATION    =>  true,
      CURLOPT_MAXREDIRS         =>  10,
      CURLOPT_TIMEOUT           =>  30,
      CURLOPT_CUSTOMREQUEST     =>  'GET',
    ));

    $response = curl_exec($curl);
    $err = curl_error($curl);

    if ($err) 
        ```Joomla log error code
    else 
        $json = json_decode($response);

                ``` update the record into table with decode json array object
    curl_close($curl);
}

After 30 odd records script returns blank response. If we execute same script again it gives the result. Script should execute for at least 3000 records without fail instead of giving correct result for 30 records only.