Example #1
0
 /**
  * TuiyoAPI::getURL()
  * Gets content from the specified URL
  * @param mixed $URL
  * @return response
  */
 public function getURL($url)
 {
     TuiyoLoader::helper("parameter");
     $params =& TuiyoParameter::load("global");
     $prName = $params->get("serverHttpProxyName", null);
     $prPort = $params->get("serverHttpProxyPort", null);
     //If requesting via proxy User other method
     if (!empty($prName) && !empty($prPort)) {
         return TuiyoAPI::getUrlViaProxy($url, $prName, $prPort);
     }
     $parsed = parse_url($url);
     $host = $parsed["host"];
     $port = !isset($parsed["port"]) || $port == 0 ? 80 : $parsed["port"];
     $path = $parsed["path"];
     if ($parsed["query"] != "") {
         $path .= "?" . $parsed["query"];
     }
     $out = "GET {$path} HTTP/1.0\r\nHost: {$host}\r\n\r\n";
     $fp = fsockopen($host, $port, $errno, $errstr, 30);
     $content = null;
     $body = false;
     $header = "";
     $bytes = fwrite($fp, $out);
     do {
         $header .= fgets($fp, 128);
     } while (strpos($header, "\r\n\r\n") === false);
     while (!feof($fp)) {
         $lfp = fgets($fp, $bytes);
         $content .= $lfp;
         //if ( $body ) $content.= $lfp;
         //if ( $lfp == "\r\n" ) $body = true;
     }
     fclose($fp);
     return $content;
 }