1
我使用外部源來獲取用戶的位置以訪問我的網站,以便我可以自定義該位置的位置,但是我使用的外部源有時可能非常緩慢,因此會減慢我的速度網站下來我得到的外部數據使用cURL
和我已經實現了一個超時功能curl_setopt($ch,CURLOPT_TIMEOUT,1000);
但一旦超時已在頁面中停止加載和一半的頁面丟失。在設置時間後停止腳本執行
這是腳本是用在我的網站
$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.
如果任何人有任何想法如何停止$ geoplugin但繼續加載這將是大加讚賞的頁面。
嘗試例外循環。 http://nz.php.net/exceptions – 2012-04-15 19:45:31
@Dagon:hehe,php.net透露你的位置,而不需要訪問個人資料:-) – zerkms 2012-04-15 23:17:39