循环停在65536

时间:2014-08-08 22:38:13

标签: php

我循环直到500000并且它停在65536,死了这个php限制或系统限制?无论如何要避免它?

不过,这只是一个普通的for循环。 for($i=0; $i<500000; $i++){}

真实的代码,我关心负载,但我担心的不是那个。

class ECStun{
    var $sp = 1;
    var $d = 5;
    var $url = 'http://example.com/';
    var $html = '';
    var $invalid = '404';

    var $data = array();

    var $db = false; // db connection
    var $dbhost = 'localhost';
    var $dbuser = 'root';
    var $dbpass = '';
    var $dbname = 'scrape';
    var $tbname = 'ecstun'; // this table will be created automatically by the script.

    var $proxies = array(
    );

    var $startat = 0;

    function init(){
        $this->initDB();
        $this->startat =  microtime(true);
        $x = rand(0, count($this->proxies)-1);
        print('start scraping using proxy : '.$this->proxies[$x]."\n");
        for($i = $this->sp; $i <= $this->d; $i++){
            $url = $this->url.'ES'.$i;
            if(!$this->isSaved($url)){ // skip is already saved to DB
                $link = curl_init();
                if(count($this->proxies) > 0){
                    curl_setopt($link, CURLOPT_PROXY, $this->proxies[$x]);
                }
                curl_setopt($link, CURLOPT_URL, $url);
                curl_setopt($link, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17)');
                curl_setopt($link, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($link, CURLOPT_FOLLOWLOCATION, true);
                $this->html = curl_exec($link);
                $code = curl_getinfo($link, CURLINFO_HTTP_CODE);
                curl_close($link);
                if($code == 200 || $code == 301){
                    $this->parse($url);
                }else{
                    /*
                    ** this block of script will make sure if IP got banned then delete the banned ip
                    ** and then check if there is another remaining IPs we can use
                    ** if no more IPs in $proxies then exit the script with information of latest ES
                    */
                    //unset($this->proxies[$x]);
                    array_splice($this->proxies, $x, 1);
                    if(count($this->proxies) > 0){
                        $this->sp = $i; // if banned then set starting point to the latest ES to try again using different ip
                        $this->init();
                    }else{
                        exit('LAST ES: ES'.$i);
                    }
                }
            }
        }
        //$this->initDB();
    }
}

$ecs = new ECStun;
if(isset($_GET['verify_proxy'])){ // browser only
    $ecs->verifyProxy();
}else{
    $ecs->init();
}

1 个答案:

答案 0 :(得分:0)

65535是一个神奇的数字。来自wikipedia

  

65535经常出现在计算领域,因为它是   可以用无符号16位二进制表示的最大数字   号。

试试这个:

var_dump(PHP_INT_MAX);

确认您的错误应该是65535。尝试升级到32位或更多。