我需要在循環內發送一些HTTP請求來刷新數據庫的幾行。 我採用此代碼做到這一點:
<?php
function insertPalineForLine($line, $noprompt, $showLines, $device){
$url2="http://www.miafoto.it/iPhone/inarrivo/php/getStations.php?linea=".$line."&noprompt=".$noprompt;
//echo "url2=".$url2."<br>";
$html2 = file_get_html($url2);
$position=0;
$previousPalette=0;
foreach($html2->find('station') as $stations) {
foreach($stations->find('palina') as $paletta);
foreach($stations->find('name') as $name);
$paletta=$paletta->plaintext;
$address=$name->plaintext;
$piecesPaletta=explode("?", $paletta);
$paletta=$piecesPaletta[0];
$url3="http://www.miafoto.it/iPhone/inarrivo/php/insertPaletta.php?previousPalette=$previousPalette&position=$position&address=$address&paletta=$paletta&line=$line";
echo $url3;
$html3 = file_get_html($url3);
$position++;
$previousPalette=$paletta;
sleep(2);
}
echo "fine foreach".$counter;
$counter++;
$url4="http://www.miafoto.it/iPhone/inarrivo/php/assignNext.php?linea=$line";
$html4 = file_get_html($url4);
}
?>
然而,即使所有的HTTP請求被髮送,只是6行了超過40的被更新(總是0,1,9,31,32,38的任何https執行者我使用)。如果我手動執行缺少的http命令(例如第3個),它們會定期填充,因此我認爲這些請求之間存在一定的干擾。我怎樣才能在沒有這種問題的情況下連續發送它們?
你完全確定嵌套的'foreach'循環嗎?我相信他們可能是這裏的問題,因爲他們什麼都不做。 – maialithar
17個問題,你沒有接受任何答案? Abismal。 – Flukey
在其他用戶收到一個答案之前,我經常會自己找到答案,而且我沒有關於如何關閉請求的提示。至於那些我沒有找到答案的人,不幸的是,我並沒有多次獲得其他好用戶的接受。最後一個關於xcode編程的問題我不得不作爲一個事件提交給Apple。 –