【发布时间】:2010-11-09 22:58:58
【问题描述】:
我已经编写了一个脚本来对一些点进行地理编码,这些点的结构基本上是这样的:
//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')
}
问题在于,即使地理编码成功并更新了数据库,并且重新发送了标头,脚本仍会返回到 while 循环,而无需重新加载页面并重新开始新记录。
这是 PHP 的正常行为吗?我该如何避免它出现这样的行为?
【问题讨论】:
-
我有点疑惑,为什么要重新加载页面?
-
为了保持一致,考虑在 : --
Location: http...-- 之后放置一个空格 -- 并确保 exit(); -
重新加载页面的原因是我无法将 php 作为 CGI 运行,如果我告诉一个页面迭代太多次它就会超时。重新加载页面使我能够在没有任何超时的情况下进行尽可能多的迭代。
标签: php header geocoding while-loop