public function request(array $params) { $request = new \HttpRequest($this->getTransmissionURL(), "POST"); $request->addBody(json_encode($params)); $this->client->attach($request); return $this->client->send(); }
public function addFeeds($urls) { $pool = new HttpRequestPool(); foreach ($urls as $url) { $pool->attach($r = $this->setupRequest($url)); } $pool->send(); foreach ($pool as $request) { $this->handleResponse($request); } }
/** * Sends a request pool. * * @param \ArrayObject $requestList Request list * @return \HttpRequestPool * @throws \Jyxo\Webdav\Exception On error */ private function sendPool(\ArrayObject $requestList) { try { // Clean the pool $this->pool->reset(); // Attach requests foreach ($requestList as $request) { $this->pool->attach($request); } // Send $this->pool->send(); return $this->pool; } catch (\HttpException $e) { // Find the innermost exception $inner = $e; while (null !== $inner->innerException) { $inner = $inner->innerException; } throw new Exception($inner->getMessage(), 0, $inner); } }
<?php try { $p = new HttpRequestPool(); // if you want to set _any_ options of the HttpRequest object, // you need to do so *prior attaching* to the request pool! $p->attach(new HttpRequest('http://pear.php.net', HTTP_METH_HEAD)); $p->attach(new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD)); } catch (HttpException $e) { print $e; exit; } try { $p->send(); // HttpRequestPool implements an iterator over attached HttpRequest objects foreach ($p as $r) { echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n"; } } catch (HttpException $e) { print $e; }
#!/usr/bin/env php <?php try { $pool = new HttpRequestPool(new HttpRequest('http://www.google.com/', HttpRequest::METH_HEAD), new HttpRequest('http://www.php.net/', HttpRequest::METH_HEAD)); $pool->send(); foreach ($pool as $request) { printf("%s is %s (%d)\n", $request->getUrl(), $request->getResponseCode() ? 'alive' : 'not alive', $request->getResponseCode()); } } catch (HttpException $e) { echo $e; }
/** * Test HttpRequestPool. */ function test_HttpRequestPool() { $http = new HttpRequestPool(); $http->send(); }