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); }
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); }
/** * 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; }