Esempio n. 1
0
 /**
  * Fetches data from $uri
  *
  * @param string $uri
  * @return string
  */
 protected function fetch($uri)
 {
     $this->bot->log("Fetching from URI: " . $uri);
     // create curl resource
     $ch = curl_init();
     // set url
     curl_setopt($ch, CURLOPT_URL, $uri);
     //return the transfer as a string
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
     // $output contains the output string
     $output = curl_exec($ch);
     // close curl resource to free up system resources
     curl_close($ch);
     $this->bot->log("Data fetched: " . $output);
     return $output;
 }
Esempio n. 2
0
 /**
  * Fetches data from $uri
  *
  * @param string $uri
  * @return string
  */
 protected function fetch($uri)
 {
     $this->bot->log("Fetching from URI: " . $uri);
     // create curl resource
     $ch = curl_init();
     // set url
     curl_setopt($ch, CURLOPT_URL, $uri);
     // Set a user agent. Some sites require it (e.g. GitHub API).
     curl_setopt($ch, CURLOPT_USERAGENT, 'WildPHP/IRCBot');
     //return the transfer as a string
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
     // $output contains the output string
     $output = curl_exec($ch);
     // close curl resource to free up system resources
     curl_close($ch);
     $this->bot->log("Data fetched: " . $output);
     return $output;
 }