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)

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

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用