2012-01-01 69 views
1

我已經做了一個基本的網絡抓取工具來從網站上抓取信息,我估計它應該花費大約6個小時(頁數乘以需要多長時間以獲取信息),但在大約30-40分鐘循環我的功能後,它停止工作,我只有我想要的信息的一小部分。當它工作時,頁面看起來像正在加載,並輸出它在屏幕上的位置,但是當它停止時,頁面停止加載並且輸入停止顯示。PHP腳本應該需要6小時,但30分鐘後停止

是否有,我可以保持頁面加載,所以我不必每30分鐘再次啓動一次?

編輯:這裏是我的代碼

function scrape_ingredients($recipe_url, $recipe_title, $recipe_number, $this_count) { 
    $page = file_get_contents($recipe_url); 

    $edited = str_replace("<h2 class=\"ingredients\">", "<h2 class=\"ingredients\"><h2>", $page); 

    $split = explode("<h2 class=\"ingredients\">", $edited); 
    preg_match("/<div[^>]*class=\"module-content\">(.*?)<\\/div>/si", $split[1], $ingredients); 

    $ingred = str_replace("<ul>", "", $ingredients[1]); 
    $ingred = str_replace("</ul>", "", $ingred); 
    $ingred = str_replace("<li>", "", $ingred); 
    $ingred = str_replace("</li>", ", ", $ingred); 

    echo $ingred; 
    mysql_query("INSERT INTO food_tags (title, link, ingredients) VALUES ('$recipe_title', '$recipe_url', '$ingred')"); 

    echo "<br><br>Recipes indexed: $recipe_number<hr><br><br>"; 

} 

$get_urls = mysql_query("SELECT * FROM food_recipes WHERE id>3091"); 
while($row = mysql_fetch_array($get_urls)) { 
    $count++; 
    $thiscount++; 
    scrape_ingredients($row['link'], $row['title'], $count, $thiscount); 

    sleep(1); 
} 

回答

6

什麼是您的php.ini的set_time_limit選項值?它必須設置爲0,以便腳本能夠無限工作

+0

我將它設置爲零,並將其修復!謝謝 :) – 2kan 2012-01-01 07:39:36

6

試着在你的腳本的頂部添加

set_time_limit(0);