如何自动收集数据,而不是冻结在10% [英] How to automate data gathering and not freeze in 10%

查看:154
本文介绍了如何自动收集数据,而不是冻结在10%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//pastebin.com/virLR7dFrel =nofollow> http://pastebin.com/virLR7dF )

(看看我的情况的图像: http://iv.pl/images/47143498348127804676.png



我有一个PHP脚本来抓取给定的网站,并将数据提取为变量:

  $ ID =data; //这只是一个例子
$ name =data;
$ price =data;
$ image =data;

脚本会将这些数据放在MySQL数据库中。



什么是错的?

我可以用for循环自动执行它,所以我会一次获得更多的数据。但是如果我循环100万次,我的脚本会在某个时候冻结,从(找到它从哪里开始,从那里开始)有问题。



PHP / JS如何使它: / b>

2。停止并显示有关收集的资料的信息。 收集下面10个部分的数据

4。停止并添加新的信息到以前显示的信息

* 有一个PAUSE功能,可以在收集下一部分后停止。

* 输入缓冲可能会帮助你在PHP



试试 ob_start & ob_flush


ob_start 此功能将打开输出缓冲。当输出
缓冲处于活动状态时,不会从脚本发送输出(而不是
标题),而是将输出存储在内部缓冲区中。

ob_flush 这个函数会发送输出缓冲区的内容(如果
any)


What I have:

(take a look or fire on localhost if required: http://pastebin.com/virLR7dF)

(take a look on image presenting my case: http://iv.pl/images/47143498348127804676.png)

I have a PHP script that crawles given websites, and extracts data as varibles:

$ID = "data"; //this is just an example
$name = "data";
$price = "data";
$image = "data";

Script will put this data in a MySQL DB.

What is wrong?

I can automate it with a for loop so I will get more data at once. But if I loop it 1,000,000 times my script will freeze at some point, and starting over (finding where it broke and starting from that point) is problematic.

How with PHP/JS make it to:

1. gather 10 portions of data

2. stop and display information about gathered data

3. gather next 10 portions of data

4. stop and add new information to previosly displayed information

* have a PAUSE function to stop after next portion gathered

* have a RESUME funcion to start after last portion gathered

解决方案

Output Buffering might be helping you in PHP

Try ob_start & ob_flush

ob_start This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

ob_flush This function will send the contents of the output buffer (if any)

这篇关于如何自动收集数据,而不是冻结在10%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆