/** * Create a new request and add it to the queue * * @param string $url * @param string $method * @param array $options */ public function addRequest($url, $options = []) { if (!$this->checkRequest($url)) { return false; } $newRequest = new Request($url); $newRequest->setOptions($this->buildOptions()); // $this->getWebCache()->add($url); $this->add($newRequest); $this->numRequests++; }
/** * Create new Request and add it to the request queue * * @param string $url * @param string $method * @param array|string $postData * @param array $headers * @param array $options * @return RollingCurl */ public function request($url, $method = "GET", $postData = null, $headers = null, $options = null) { $newRequest = new Request($url, $method); if ($postData) { $newRequest->setPostData($postData); } if ($headers) { $newRequest->setHeaders($headers); } if ($options) { $newRequest->setOptions($options); } return $this->add($newRequest); }
/** * Sends rolling curl multirequest. * @param array $data curl request data as [url, url, ...] or [url=>['post'=>[...], 'files'=>[...]]] * @param \Closure $callback callback at response. */ public function multiRequest($data, $callback) { $rollingCurl = new RollingCurl(); foreach ($data as $url => $options) { if (is_string($options)) { $url = $options; } if ($this->unique && in_array($url, $this->visited) && !@$options['post']) { continue; } else { $this->visited[] = $url; } $method = isset($options['post']) ? 'POST' : 'GET'; $request = new Request($url, $method); $curlOptions = $this->getCurlOptions($url, @$options['post'], @$options['files']); $request->setOptions($curlOptions); $rollingCurl->add($request); } $rollingCurl->setCallback($callback)->execute(); }