如何執行該循環:PHP凍結:如何循環連接到2個MySQL數據庫
while ($row = mysql_fetch_array($result)) {
collectData($row['NAME']);
}
30秒後未凍結我的PHP?
我認爲可以通過將整個數據庫轉換爲數組或* .temp文件來處理它,而不是每次我想要輸入/輸出時連接。但是我在文件和數組上遇到了問題,所以我就這樣問:爲什麼最好/最好的方法快速而無痛地做到這一點?
<?php
//fiveMin - Database that data is taken form
//HighCharts - Database that data is transferred to
$fiveMin=mysql_connect($fiveMin_host,$fiveMin_user,$fiveMin_pass);
mysql_select_db($fiveMin_db,$fiveMin) or die (mysql_error());
$query="SELECT * FROM BetterShopItemStock";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
collectData($row['NAME']);
}
function collectData($itemID) {
global $fiveMin_host, $fiveMin_user, $fiveMin_pass, $fiveMin_db, $week_host, $week_user, $week_pass, $week_db;
$fiveMin=mysql_connect($fiveMin_host,$fiveMin_user,$fiveMin_pass); //Load and store data from fiveMin Database
mysql_select_db($fiveMin_db,$fiveMin) or die (mysql_error());
$function_Query="SELECT AMT FROM BetterShopItemStock WHERE NAME = '$itemID'";
$function_Ask = mysql_query($function_Query);
$function_Result = mysql_fetch_row($function_Ask, 0);
$dataReadyToImport = "," . $function_Result[0];
@mysql_close($fiveMin);
$HighCharts=mysql_connect($week_host,$week_user,$week_pass); //Save stored data to weekly Database
mysql_select_db($week_db,$HighCharts) or die (mysql_error());
$function_Query="SELECT AMT FROM BetterShopItemStock WHERE NAME = '$itemID'";
$function_Ask = mysql_query($function_Query);
$function_Result = mysql_fetch_row($function_Ask, 0);
$storedData = $function_Result[0];
$dataReadyToImport = $storedData . $dataReadyToImport;
mysql_query("UPDATE BetterShopItemStock SET AMT='$dataReadyToImport' WHERE NAME='$itemID'");
@mysql_close($HighCharts);
}
?>
由於30秒的(默認)最大執行時間已經過去,PHP是否凍結或死亡? – drew010 2012-07-20 00:34:08
它的停止速度甚至超過了30秒,但表示它延長了它。 – IlikeITalot 2012-07-20 06:53:42