English 中文(简体)
体重分享模块和PHP报废
原标题:The bwshare module and PHP scraping

我从网站下载网页列表时写了一个脚本。 我经常收到以下错误( 秒数是变量) :

The bwshare module will refuse your requests for the next 7 seconds. You have downloaded data too rapidly.

I found when using sleep(2) in the loop, it works much better, however the time delay is too expensive. What s the best way how to deal with this module? Should I scrape it without any delay and if the response will be similar to the above message simply use sleep for the requested number of seconds?

最佳回答

这都取决于在错误消息之前您可以得到多少页。

尝试测量您平均可以得到多少页 。

最起码须在体重共享信息之前 < 强> 4页。

如果您在 < / em> 下载到 4 页之前收到错误消息 < em>, il 将在每次下载后< em> faster 入睡(2) 。

问题回答

这样试试... 可能会有帮助

  $requestTime = 0.1; // s/connection

    foreach(/* blah */) {
        $start = microtime(true);
        // Do your stuff to here.. get_file_content($url) and other processing .........

        if($timeTaken = microtime(true)-$start < $requestTime) {
            usleep(($requestTime-$timeTaken)*1000000);
        }
    }

如果问题解决了,请公布答案,以便其他人也受益。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签