2012-04-15 4 views
1

외부 소스를 사용하여 내 웹 사이트 사용자 위치를 얻으므로 사이트를 사용자 정의 할 수 있지만 사용하는 외부 소스가 때때로 매우 느려서 내 속도가 느려질 수 있습니다. 사이트 다운 내가 cURL을 사용하여 외부 데이터를 얻고 나는 시간 초과 기능을 구현했습니다 curl_setopt($ch,CURLOPT_TIMEOUT,1000);하지만 시간이 초과되면 페이지로드가 중단되고 페이지 절반이 누락됩니다.설정 시간이 지나면 스크립트 실행 중지

이 스크립트가 사람이 어떻게 $의 geoplugin을 중지하지만이 많이 주시면 감사하겠습니다 페이지를로드 계속하는 어떤 아이디어가 있다면 내 웹 사이트

$i = 1; 
$geoplugin = new geoPlugin(); 
$geoplugin->locate(); 
if(empty($_SESSION['country'])) { 
    $conchk = $geoplugin->countryName; 
    $_SESSION['country'] = $conchk; 
} 
else { $conchk = $_SESSION['country']; } 
if(empty($conchk)) {$countrygeo = "NULL_CONT";} else {$countrygeo = $conchk;} 
//$countrygeo = "Spain"; 
$country_find = mysql_query("SELECT * FROM country_list 
    WHERE country='$countrygeo' LIMIT 1"); 
while($row_cou = mysql_fetch_array($country_find)) { 
    $rowcov = $row_cou[1]; 
    //Geo-location default! 
    print "<option selected value=\"$rowcov\">$rowcov</option>\n"; 
    $kvar = 1; 
} 
//finish first while loop! 
//if we cant find the geo-country in the list print the whole table! 
$country_full_list_print = mysql_query("SELECT * FROM country_list 
    ORDER BY country ASC"); 
while($row_full = mysql_fetch_array($country_full_list_print)) { 
    if(($row_full[1] == "United Kingdom") && ($i == 1) && (empty($kvar))) { 
    print "<option selected value=\"$row_full[1]\">$row_full[1]</option>\n"; $i++; } 
    //always print uk as default if no results. 
elseif ($row_full[1] == $rowcov) { } 
else { 
    print "<option value=\"$row_full[1]\">$row_full[1]</option>\n"; } //this is the default print! 
} //close while loop and if num_rows less than 1. 

에 사용입니다.

+0

예외 루프를 사용해보십시오. http://nz.php.net/exceptions –

+0

@ 대각성 : hehe, php.net은 프로필을 방문 할 필요없이 귀하의 위치를 ​​공개합니다 :-) – zerkms

답변

0

외부 리소스로 호출 한 부분을 다른 스크립트로 옮기고 가능한 한 빨리 AJAX로 호출하십시오. 이렇게하면 별도의 스크립트에 엄격한 시간 제한을 부과 할 수 있습니다. 문제가 없으면 AJAX 요청은 실패하지만 정상적으로 처리 할 수 ​​있으며 페이지의 나머지 부분에는 영향을 미치지 않습니다.

느린 외부 응답으로 페이지가 하얗게 남지 않더라도 여전히 페이지에 지연이 발생합니다.

관련 문제