curlPresent() static public method

static public curlPresent ( )
Example #1
0
 /**
  * Returns an HTTP fetcher object.  If the CURL extension is
  * present, an instance of {@link Auth_Yadis_ParanoidHTTPFetcher}
  * is returned.  If not, an instance of
  * {@link Auth_Yadis_PlainHTTPFetcher} is returned.
  *
  * If Auth_Yadis_CURL_OVERRIDE is defined, this method will always
  * return a {@link Auth_Yadis_PlainHTTPFetcher}.
  */
 function getHTTPFetcher($timeout = 20)
 {
     if (Auth_Yadis_Yadis::curlPresent() && !defined('Auth_Yadis_CURL_OVERRIDE')) {
         $fetcher = new Auth_Yadis_ParanoidHTTPFetcher($timeout);
     } else {
         $fetcher = new Auth_Yadis_PlainHTTPFetcher($timeout);
     }
     return $fetcher;
 }
Example #2
0
function detect_fetcher($r, &$out)
{
    $out .= $r->h2('HTTP Fetching');
    $result = @(include 'Auth/Yadis/Yadis.php');
    if (!$result) {
        $out .= $r->p('Yadis code unavailable; could not test fetcher support.');
        return false;
    }
    if (Auth_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 is recommended. ' . 'The OpenID library will use an fsockopen()-based fetcher.');
        $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 = Auth_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!');
    }
    if ($fetcher->supportsSSL()) {
        $out .= $r->p('Your PHP installation appears to support SSL, so it ' . 'will be able to process HTTPS identity URLs and server URLs.');
    } else {
        $out .= $r->p('Your PHP installation does not support SSL, so it ' . 'will NOT be able to process HTTPS identity URLs and server URLs.');
    }
    return $ok;
}