dongren1353 2017-04-10 08:31
浏览 38

PHP脚本挂起的大型数据集

I am building a website which scrapes data from another website,stores it in a database and shows it in the form of a table. Everything works fine as long as the number of rows are less (around 100), but when the data set increases, say 300 rows or more the data gets stored in the database (phpmyadmin) but nothing shows on the screen and the site just keeps loading. Below is a section of the php script i am running:

<?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]);
    }
}?>

interestingly, if i already have the data stored in my db and I just retrieve and print it , everything works fine and all the data ,however large it is,gets printed. I have no clue whats the problem. PS : I have already tried set_time_limit().

  • 写回答

1条回答 默认 最新

  • drh37116 2017-04-10 08:47
    关注

    you are creating an infinite loop. so to fix the issue change the criteria for your while loop to the below.

    while($page<$pages)
    {
        //your same code here
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)