2

我在下面有一个 PHP 循环,它可以正常工作,但是有时 CURL 请求会返回一个错误页面,我怎样才能只重新启动当前页面的操作而不重新启动整个循环?

while ($daytofetch <= $lastdaytofetch) {

//Do all my stuff and run curl request here 

$daytofetch++

}
4

2 回答 2

2

我可能会做这样的事情:

while ($daytofetch <= $lastdaytofetch) {
    $error = false;


    //Do all my stuff and run curl request here
    //if there is an error, then set $error = true;


    if (!$error)
        $daytofetch++
}
于 2013-01-15T21:24:02.303 回答
2
while ($daytofetch <= $lastdaytofetch) {

    // Do all my stuff and run curl request here

    if ($error_detected) {
        // This will resume the loop without incrementing
        // $daystofetch
        continue;
    }

    $daytofetch++
}
于 2013-01-15T21:24:26.723 回答