Php 停止无限循环超时

Php 停止无限循环超时,php,file-get-contents,Php,File Get Contents,基本上,我有一个脚本,它使用file\u get\u contents执行无限循环,它基本上只是运行函数,然后增加传递给file\u get\u contentsurl的$\u get变量,问题显然是它抛出了一个“太多重定向”错误,这是我在Cron作业中可以实现的一种方式,还是一种没有错误的方式,这是我当前的代码 $id = $_GET['id']; $next_id = $id + 1; $url = "http://www.website.com/profile/$id.json"; $js

基本上,我有一个脚本,它使用
file\u get\u contents
执行无限循环,它基本上只是运行函数,然后增加传递给
file\u get\u contents
url的
$\u get
变量,问题显然是它抛出了一个“太多重定向”错误,这是我在Cron作业中可以实现的一种方式,还是一种没有错误的方式,这是我当前的代码

$id = $_GET['id'];
$next_id = $id + 1;
$url = "http://www.website.com/profile/$id.json";
$json = file_get_contents($url);
$result = json_decode($json, true);

$headers = get_headers($url);
if($headers[0] !== "HTTP/1.1 404 Not Found") {
  $query = mysql_query("query here");
  if($query) {
       echo '<script type="text/javascript">
       <!-- window.location = "import.php?id='.$next_id.'" //-->
       </script>';
  } else {
       echo '<script type="text/javascript">
       <!-- window.location = "import.php?id='.$id.'" //-->
       </script>';
  }
}
$id=$\u GET['id'];
$next_id=$id+1;
$url=”http://www.website.com/profile/$id.json”;
$json=文件获取内容($url);
$result=json_decode($json,true);
$headers=get_headers($url);
如果($headers[0]!==“HTTP/1.1 404未找到”){
$query=mysql_query(“此处查询”);
如果($query){
回声'
';
}否则{
回声'
';
}
}

有没有其他方法或更有效的方法?在使用重定向之前,我尝试过使用
sleep(5)
等方法,但它似乎仍在继续使用在JavaScript中尝试在重定向之前添加暂停:

echo '<script type="text/javascript">
<!-- window.setTimeout("window.location = \"import.php?id='.$next_id.'\"", 5000); //-->
</script>';
echo'
';