2017-04-10 33 views
0

我正在構建一個網站,它從另一個網站上抓取數據,將其存儲在數據庫中並以表格的形式顯示。只要行數較少(大約100),一切都可以正常工作,但是當數據集增加時,比如說300行或更多的數據存儲在數據庫(phpmyadmin)中,但屏幕上並沒有顯示任何內容,並且該站點只保留加載。下面是PHP腳本我運行的部分:php腳本懸掛大型數據集

<?php 

// configuration 
require("../includes/helpers.php"); 

     // initializing current page and number of pages 
     $page = 0; 
     $pages = 1; 

     // scrape data from each page 
     while($pages--) 
     { 
      // next page 
      $page++; 

      // scrape data from shiksha.com 
      $string = @file_get_contents("http://www.shiksha.com/b-tech/colleges/b-tech-colleges-".urlencode($_POST["city"])."-{$page}"); 

      if($string === false) 
       apologize("Please enter a valid city name"); 

      if($page === 1) 
      { 
       // counting total number of pages 
       preg_match_all('/class=" linkpagination">/',$string,$result); 
       $pages = sizeof($result[0]); 
      } 

      // passing the string for scraping data and storing in database 
      get_college_info($string,$page); 

      // delay for 2s 
      sleep(2); 
     } 


     // querying the infrastructure table for facilities of all colleges 
     $infra = query("SELECT college_id,facilities FROM infrastructure "); 

     // preparing query and selecting data from table college_info 
     $result = query("SELECT * FROM college_info"); 

     // render(output) results 
     render("result.php",["title" => "result","infra" => $infra,"result" => $result]); 
    } 
}?> 

有趣的是,如果我已經有存儲在我的數據庫中的數據,我只是檢索和打印,一切工作正常,所有的數據,但是大型IT是,打印出來。我不知道最新的問題。 PS:我已經試過set_time_limit()。

回答

0

您正在創建一個無限循環。因此要解決該問題,請將您的while循環的標準更改爲以下內容。

while($page<$pages) 
{ 
    //your same code here 
} 
+0

我不認爲多數民衆贊成在問題,無論如何我試過了,它仍然沒有工作。 @ user3299379 –