Exemple #1
0
        throw new Exception("I couldn't fetch the response.");
    }
    printf("Single request: Success: %s\n", $response);
    printf("I downloaded %n bytes!\n", $curl->info('size_download'));
    // Now we'll test the parallel processor
    /**
     * Let's fetch Yahoo
     */
    $y = new Curl("http://www.yahoo.com/");
    /**
     * And let's grab Google, too
     */
    $g = new Curl("http://www.google.com/");
    /**
     * Create a CurlParallel object
     */
    $m = new CurlParallel($y, $g);
    $m->exec();
    if (strlen($g->fetch()) && strlen($y->fetch())) {
        printf("Parallel requests: Success!");
    } else {
        throw new Exception("Could not run in parallel.");
    }
} catch (Exception $e) {
    // There was a problem! What happened?
    printf("Oh Noes!\n");
    printf("%s\n", $e->getMessage());
    if ($curl) {
        printf("cURL error: %s\n", $curl->errno());
    }
}
Exemple #2
0
 public function globalAuth()
 {
     global $_USERID;
     $url = ROOT_AUTH . "authentication/";
     $headers = array("Api-Code: " . API_NAME);
     $headers[] = "Authorization: " . str_replace("Global ", "", $this->request->headers->authorization());
     $options = array(CURLOPT_URL => $url, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_HTTPHEADER => $headers);
     $curl = new Curl();
     $result = $curl->fetch($options);
     if ($result->code < 300) {
         $this->permissions = $result->body->permissions;
         $_USERID = $result->body->userId;
         return true;
     } else {
         $this->response->status($result->code);
     }
 }
Exemple #3
0
 public function fetchXML($url)
 {
     if (function_exists('apc_fetch')) {
         $expiry = apc_fetch('expiry');
         if (!$expiry || $expiry < time()) {
             apc_clear_cache();
             apc_clear_cache('user');
             apc_store('expiry', time() + config('apc.expiry'));
         }
         if (apc_fetch($url)) {
             $results = apc_fetch($url, $results);
         } else {
             $results = Curl::fetch($url, true);
             apc_store($url, $results);
         }
     } else {
         $results = Curl::fetch($url, true);
     }
     $string = simplexml_load_string($results);
     if ($string === FALSE) {
         Debug::error("Not XML");
         return false;
     } else {
         $oXML = new SimpleXMLElement($results);
         return $oXML;
     }
 }