2012-04-14 10 views
8

निरस्त करना चाहता हूं, मैं एक क्रॉलर बनाना चाहता हूं जो सभी पृष्ठों की सूचनाओं को 0 से 10 000 000 से एक करके ले लेता है। मुझे कोई फर्क नहीं पड़ता कि यह कितना समय लगता है। मैं बस यह काम करना चाहता हूँ। यहाँ त्रुटि मैं प्राप्त'100' का अधिकतम फ़ंक्शन घोंसला स्तर

Fatal error: Maximum function nesting level of '100' reached, aborting! in D:\wamp\www\crawler\index.php on line 25

लाइन 25

$htmlstr = (string)$this->curlGet($url); 

है और वहाँ मेरा पूरा स्क्रिप्ट है।

आपकी मदद के लिए धन्यवाद!

header('Content-Type: text/html; charset=utf-8'); 
ini_set('max_input_nesting_level','100000'); 
ini_set('max_execution_time','100000'); 

class crawler{ 

    private $url; 
    private $page; 
    private $bothurl; 
    private $innerDom = null; 
    public $prop; 
    public $entry; 

    function __construct($entry){ 
     $this->entry = $entry; 
     $this->bothurl = array('http://www.remax-quebec.com/fr/inscription/Q/'.$entry.'.rmx','http://www.remax-quebec.com/en/inscription/Q/'.$entry.'.rmx'); 
     $this->scan(); 
    } 

    private function scan(){ 
     $i =0; 
     foreach($this->bothurl as $url){ 
      $this->url = $url; 
      $this->lang = ($i==0)?'fr':'en'; 
      $htmlstr = (string)$this->curlGet($url); 
      $dom = new DOMDocument; 
      @$dom->loadHTML($htmlstr); 
      $this->page = $dom; 
      $this->htmlInfos(); 
      $this->getInfos(); 
      $i++; 
     } 
    } 

    private function htmlInfos(){ 
     $divs = $this->page->getElementsByTagName('div'); 
     foreach($divs as $div){ 
      if($div->hasAttribute('class') && $div->getAttribute('class') == 'bloc specs'){ 
       $innerDom = new DOMDocument(); 
       @$innerDom->loadHTML($this->innerHTML($div)); 
       $this->innerDom = $innerDom; 
      } 
     } 
     if($this->innerDom === null) $this->changeEntry(); 
    } 

    private function getInfos(){ 
     $sect = 0; 

     foreach($this->innerDom->getElementsByTagName('div') as $div){ 
     # obtenir la description 
      $this->getDesc($div->getAttribute('class'),$div); 
     # obtenir les caractéristiques 
      $this->getCaract($div->getAttribute('class'),$div); 
     # obtenir les informations interieur, exterieur et evaluation 
      if($div->getAttribute('class') == 'section deux-colonnes'){ 
       switch($sect){ 
        case 0: $this->getSpecInfos($div,'interieur'); break; 
        case 1: $this->getSpecInfos($div,'exterieur'); break; 
        case 2: $this->getSpecInfos($div,'evaluation'); break; 
        case 3: $this->getSpecInfos($div,'equipement'); break; 
        case 4: $this->getSpecInfos($div,'services'); break; 
       } 
       $sect++; 
      }else if($div->getAttribute('class') == 'section'){ 
     # obtenir les détails des pièces 
       foreach($div->getElementsByTagName('table') as $table){ 
        if($table->getAttribute('class') == 'details-pieces'){ 
         $this->detailPieces($table); 
        } 
       } 
      } 
     } 
    } 

    private function getDesc($class,$obj){ 
     if($class == 'section description'){ 
      $p = $obj->getElementsByTagName('p')->item(0); 
      $text = (string)$p->nodeValue; 
      $this->prop[$this->lang]['description'] = $text; 
     } 
    } 

    private function getCaract($class,$obj){ 
     if($class == 'section characteristiques'){ 
      foreach($obj->getElementsByTagName('div') as $div){ 
       if(substr($div->getAttribute('class'),0,4) == "item"){ 
        $text = (string)$div->nodeValue; 
        $this->prop[$this->lang]['caracteritiques'][substr($div->getAttribute('class'),5)] = $text; 
       } 
      } 
     } 
    } 

    private function getSpecInfos($obj,$nomInfo){ 
     foreach($obj->getElementsByTagName('table') as $table){ 
      foreach($table->getElementsByTagName('tr') as $tr){ 
       $name = $tr->getElementsByTagName('td')->item(0); 
       $value = $tr->getElementsByTagName('td')->item(1); 
       $name = substr((string)$name->nodeValue,0,-2); 
       $value = (string)$value->nodeValue; 
       $this->prop[$this->lang][$nomInfo][$this->noAccents($name)] = $value; 
      } 
     } 
    } 

    private function detailPieces($obj){ 
     $tbody = $obj->getElementsByTagName('tbody')->item(0); 
     foreach($tbody->getElementsByTagName('tr') as $tr){ 
      $name = $tr->getElementsByTagName('td')->item(0); 
      $name = (string)$name->nodeValue; 
      $level = $tr->getElementsByTagName('td')->item(1); 
      $level = (string)$level->nodeValue; 
      $dimensions = $tr->getElementsByTagName('td')->item(2); 
      $dimensions = (string)$dimensions->nodeValue; 
      $floor = $tr->getElementsByTagName('td')->item(3); 
      $floor = (string)$floor->nodeValue; 
      $desc = $tr->getElementsByTagName('td')->item(4); 
      $desc = (string)$desc->nodeValue; 

      $this->prop[$this->lang]['pieces'][$this->noAccents($name)]['etage'] = $level; 
      $this->prop[$this->lang]['pieces'][$this->noAccents($name)]['dimensions'] = $dimensions; 
      $this->prop[$this->lang]['pieces'][$this->noAccents($name)]['revetement'] = $floor; 
      $this->prop[$this->lang]['pieces'][$this->noAccents($name)]['description'] = $desc; 
     } 
    } 

    private function innerHTML($element){ 
     $innerHTML = ""; 
     $children = $element->childNodes; 
     foreach ($children as $child) 
     { 
      $tmp_dom = new DOMDocument(); 
      $tmp_dom->appendChild($tmp_dom->importNode($child, true)); 
      $innerHTML.=trim($tmp_dom->saveHTML()); 
     } 
     return $innerHTML; 
    } 

    private function noAccents($value){ 
     $string= strtr($chaine,"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ","aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn"); 
    } 

    private function changeEntry(){ 
     $this->entry++; 
     echo $this->entry; 
     $this->scan(); 
    } 

    private function curlGet($url){ 
     $curl = curl_init(); 
     curl_setopt($curl, CURLOPT_URL, $url); 
     curl_setopt($curl, CURLOPT_ENCODING, "gzip"); 
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
     $data = curl_exec($curl); 
     curl_close($curl); 
     return $data; 
    } 
} 

$entry = 8678057; 

$crawler = new crawler($entry); 

echo '<pre>'; 
print_r($crawler->prop); 
echo '</pre>'; 
+2

क्या आप Google को पुन: पेश कर रहे हैं? –

+3

मुझे इस मुद्दे को समझने की कोशिश करने के लिए यहां वास्तव में प्रयास नहीं दिख रहा है। – simchona

+3

आपको एक त्रुटि मिली है।यह अच्छा है। आपने कोड पोस्ट किया है यह भी अच्छा है, लेकिन आपका सवाल कहां है? क्या आप चाहते हैं कि हम आपके कोड को जादुई रूप से ठीक करें और यहां एक समाधान समाधान पोस्ट करें? – Bojangles

उत्तर

33

मान लिया जाये कि आप xdebug का उपयोग कर रहे हैं, तो आप के साथ

ini_set('xdebug.max_nesting_level', $limit) 
+0

बूटस्ट्रैप संकलित करने के लिए laravel 4 में less.php के लिए प्लगइन के साथ संपत्ति का उपयोग करके, मैंने 100 अधिकतम त्रुटि को दबाया, 200 से बढ़ने से इसे चलाने की अनुमति मिलती है। वैध लगता है। –

2

कि max_allowed_packet = 512 एम

की तरह कुछ करने के लिए पैरामीटर /etc/mysql/my.cnf फ़ाइल में परिवर्तन अपनी खुद की सीमा निर्धारित कर सकते

सुनिश्चित करें कि आप मिल गया xdebug स्थापित किया है जाओ (उपयोग phpinfo()) और फिर जोड़ते या संपादित लाइन फ़ाइल /etc/php5/fpm/php.ini बदलने के लिए: xdebug.max_nesting_level = 1000

+०१२३५१६४१०

पुनरारंभ दोनों सेवाओं sudo सेवा mysql पुनः आरंभ sudo सेवा PHP5-एफ पी एम पुनः आरंभ

यह आप अभी भी /etc/php5/fpm/php.ini xdebug पर गलत पर उन दो मापदंडों सेट कर सकते हैं काम नहीं करता है। remote_autostart = 0 xdebug.remote_enable = 0

1

मेरे मामले में, यह संगीतकार से संबंधित था। कुछ विक्रेताओं को composer.json फ़ाइल में अपडेट किया गया था, लेकिन मैं आदेश संगीतकार अद्यतन और न ही संगीतकार स्थापित करने के लिए भूल गया था। इस प्रणाली ने इर्रोस का एक कैस्केड उत्पन्न किया, जो इस 'अधिकतम घोंसला वाले स्तर' का कारण बन रहा था।

उन आदेशों को क्रियान्वित करने के बाद, समस्या

0

तय किया गया था मान लें कि आप एक ड्रॉप मृत पड़ाव गलती नहीं था, सिर्फ xdebug की सीमा बदल जाते हैं।

मैंने xdebug.ini फ़ाइल को बदलकर इस समस्या को धीमा कर दिया। (मेरे मैक में, पथ /usr/local/php5-5.6.17-20160108-103504/php.d/50-extension-xdebug.ini है, हो सकता है तुम्हारा थोड़ा अलग होगा।)

xdebug.ini फ़ाइल के तल पर एक नई लाइन जोड़ें:

xdebug.max_nesting_level = 500


याद रखें: आप xdebug.ini php प्रयोग कर रहे हैं करने के लिए इसी को बदलना होगा। उदाहरण के लिए, यदि आपने अपने कंप्यूटर में php5 और xampp स्थापित किया है, तो आपको यह पता लगाना होगा कि आप किस PHP का उपयोग कर रहे हैं।

संबंधित मुद्दे