Exemple #1
0
 function __construct($url, $headers = array())
 {
     // prepare headers
     $h = array();
     foreach ($headers as $name => $val) {
         if (strlen($val) > 0) {
             $h[] = $name . ': ' . $val;
         }
     }
     // build request
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     if (count($h) > 0) {
         curl_setopt($curl, CURLOPT_HTTPHEADER, $h);
     }
     parent::__construct($curl);
 }
Exemple #2
0
 function __construct($url, $content, $headers = array())
 {
     // prepare headers
     $h = array();
     foreach ($headers as $name => $val) {
         if (strlen($val) > 0) {
             $h[] = $name . ': ' . $val;
         }
     }
     // if content is array, parse to string
     if (is_array($content)) {
         $content = http_build_query($content, null, '&');
     }
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
     if (count($h) > 0) {
         curl_setopt($curl, CURLOPT_HTTPHEADER, $h);
     }
     parent::__construct($curl);
 }
Exemple #3
0
 /**
  * This blocks until a particular request is complete.
  *
  * @param T_Curl_Request $request  request to wait on
  * @return T_Curl  fluent interface
  */
 function waitFor(T_Curl_Request $request)
 {
     $key = (string) $request->getHandle();
     if (!$this->isKey($key)) {
         $msg = "No queued CURL request with key {$key}";
         throw new T_Exception_Curl($msg);
     }
     while (!$this->ping($request)) {
         usleep(50);
         // pause before trying again
     }
     return $this;
 }