Exemple #1
0
 protected function init()
 {
     if (!extension_loaded('curl')) {
         exit('Need curl extension');
     }
     if ($this->ch) {
         return true;
     }
     try {
         $this->ch = curl_init();
         curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
         if (!empty($this->buffer)) {
             curl_setopt($this->ch, CURLOPT_BUFFERSIZE, $this->buffer);
         }
         if (\Config::get('parser.userAgent')) {
             curl_setopt($this->ch, CURLOPT_USERAGENT, UserAgent::random_user_agent());
         }
         if (\Config::get('parser.proxy')) {
             curl_setopt($this->ch, CURLOPT_PROXY, $this->getProxy());
         }
         if (\Config::get('parser.timeout')) {
             curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, \Config::get('parser.timeout'));
         }
     } catch (\Exception $e) {
         return $e;
     }
     return true;
 }