while循环与PHP中的header()结合使用

whe*_*hys 1 php geocoding header while-loop

我写了一个脚本来对某些点进行地理编码,这些点的结构基本上是这样的:

//get an unupdated record
$arr_record;
while(count($arr_record) > 0)
{
//strings are derived from $arr_record
geocode($string1);
geocode($string2);
geocode($string3);
array_pop($arr_record);
}

function geocode($string) {
   //if successful
      update($coords)
}

function update($coords) {
   //update the database
   header('Location:http://localhost/thisfile.php')
}
Run Code Online (Sandbox Code Playgroud)

麻烦的是,即使地理编码成功并且数据库已更新,并且标题重新发送,脚本仍会返回到while循环而不重新加载页面并重新开始新记录.

这是PHP的正常行为吗?我该如何避免它像这样?

uso*_*ban 5

在header()之后使用die(); 终止脚本和输出.