doomli3721 2015-12-11 17:47
浏览 9
已采纳

获得数百个地址的lat lng

I have a mysql database of records that holds addresses. I want to iterate through these addresses and get the geocode lat and lng for each one and put them in the database. I am using php. But when I run this code, I get an error that says "The FastCGI process exceeded configured request timeout". Does anyone have a suggestion for how to make this program work better, or if not, whether another method will work better?

include_once ('constants_test.php'); 
// connect to database
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); //open db conn
if (mysqli_connect_errno()) {
        printf("Connect failed: %s", mysqli_connect_error());
        exit();
}


function lookup($string){
    ini_set('max_execution_time', 300);
   $string = str_replace (" ", "+", urlencode($string));
   $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $details_url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   $response = json_decode(curl_exec($ch), true);

   // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
   if ($response['status'] != 'OK') {
    return null;
   }

   //print_r($response);
   $geometry = $response['results'][0]['geometry'];
    $longitude = $geometry['location']['lat'];
    $latitude = $geometry['location']['lng'];

    $array = array(
        'latitude' => $geometry['location']['lng'],
        'longitude' => $geometry['location']['lat'],

    );

    return $array;

}

$q = "SELECT ShotLocation FROM shotsfired";
 $result = $mysqli->query($q);
 $count = 0;

 while($row = $result->fetch_array(MYSQLI_ASSOC)) {
     if ($count < 3) {
         $location = $row["ShotLocation"];
         $location .= ", Pittsburgh, PA";
         $array = lookup($location);
         print_r($array);
         print_r ("<br/><br/>");
     }
    $count = $count++;
 }
  • 写回答

1条回答 默认 最新

  • dongtiao1817 2015-12-11 18:01
    关注

    You're request is most probably taking longer than the maximum allowed time for a process to run. To solve this, increase the limit of requestTimeout to something higher.

    To modify requestTimeout in IIS webserver, you can use the IIS Manager. Go to Server->IIS->FastCGI Settings/Edit.

    OR, do this. Add the below to your web config.

    <system.web>
        <httpRuntime executionTimeout="600" />
    </system.web>
    

    (600seconds = 10 minutes)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法