Exemplo n.º 1
0
 /**
  * Returns an HTTP fetcher object.  If the CURL extension is
  * present, an instance of {@link Services_Yadis_ParanoidHTTPFetcher}
  * is returned.  If not, an instance of
  * {@link Services_Yadis_PlainHTTPFetcher} is returned.
  */
 function getHTTPFetcher($timeout = 20)
 {
     if (Services_Yadis_Yadis::curlPresent()) {
         $fetcher = new Services_Yadis_ParanoidHTTPFetcher($timeout);
     } else {
         $fetcher = new Services_Yadis_PlainHTTPFetcher($timeout);
     }
     return $fetcher;
 }
Exemplo n.º 2
0
function detect_fetcher($r, &$out)
{
    $out .= $r->h2('HTTP Fetching');
    $result = @(include 'Services/Yadis/Yadis.php');
    if (!$result) {
        $out .= $r->p('Yadis code unavailable; could not test fetcher support.');
        return false;
    }
    if (Services_Yadis_Yadis::curlPresent()) {
        $out .= $r->p('This PHP installation has support for libcurl. Good.');
    } else {
        $out .= $r->p('This PHP installation does not have support for ' . 'libcurl. CURL is not required, but some functionality, ' . 'such as fetching HTTPS URLs, will be missing and ' . ' performance will not be as good.');
        $lnk = $r->link('http://us3.php.net/manual/en/ref.curl.php');
        $out .= $r->p('See ' . $lnk . ' about enabling the libcurl support ' . 'for PHP.');
    }
    $ok = true;
    $fetcher = Services_Yadis_Yadis::getHTTPFetcher();
    $fetch_url = 'http://www.openidenabled.com/resources/php-fetch-test';
    $expected_url = $fetch_url . '.txt';
    $result = $fetcher->get($fetch_url);
    if (isset($result)) {
        $parts = array('An HTTP request was completed.');
        // list ($code, $url, $data) = $result;
        if ($result->status != '200') {
            $ok = false;
            $parts[] = $r->b(sprintf('Got %s instead of the expected HTTP status code ' . '(200).', $result->status));
        }
        $url = $result->final_url;
        if ($url != $expected_url) {
            $ok = false;
            if ($url == $fetch_url) {
                $msg = 'The redirected URL was not returned.';
            } else {
                $msg = 'An unexpected URL was returned: <' . $url . '>.';
            }
            $parts[] = $r->b($msg);
        }
        $data = $result->body;
        if ($data != 'Hello World!') {
            $ok = false;
            $parts[] = $r->b('Unexpected data was returned.');
        }
        $out .= $r->p(implode(' ', $parts));
    } else {
        $ok = false;
        $out .= $r->p('Fetching URL ' . $lnk . ' failed!');
    }
    return $ok;
}