/** * Construct new response from client result * * @param Fetcher\Client * @param string $raw */ public function __construct(Client $client, $raw) { // retrieve only the last header $count = curl_getinfo($client->getHandle(), CURLINFO_REDIRECT_COUNT); $buffer = preg_split('/(\\r?\\n){2}/', $raw, $count + 2); list($header, $this->body) = array_slice($buffer, -2); // parse header $headers = preg_split('/\\r?\\n/', $header); $this->code = preg_replace('#HTTP/1.\\d (\\d{3}).*#', '$1', $headers[0]); for ($i = 1, $c = count($headers); $i < $c; ++$i) { list($key, $val) = explode(': ', $headers[$i], 2); $this->headers[strtolower($key)] = $val; } }
/** * Queue client fetch * * @param Fetcher\Client */ protected function queue(Client $client, $requeue = false) { $ch = $client->getHandle(); $key = intval($ch); $item = $client->shift(); if ($requeue && isset($this->queue[$key])) { curl_multi_remove_handle($this->mh, $ch); unset($this->queue[$key]); } if ($item) { $fn = isset($item[1]) ? $item[1] : null; $this->queue[$key] = array($client, $fn); curl_multi_add_handle($this->mh, $ch); } }