Beispiel #1
0
 /**
  * Performs parallel asyncronous GET requests to a CREST endpoint. This method has void return, instead, responses
  * are passed to the callback functions provided as arguments as they are received.
  *
  * This method will most likely be most useful in batch scripting scenarios. If the same data is requested less
  * frequently than the cache TTL, it is advisable to disable caching via argument to avoid overflowing the cache
  * with data that won't be requested again before they expire.
  *
  * @param array $hrefs the hrefs to request
  * @param callable $callback a function expecting one iveeCrest\Response object as argument, called for every
  * successful response
  * @param callable $errCallback a function expecting one iveeCrest\Response object as argument, called for every
  * non-successful response
  * @param string $accept the requested representation
  * @param bool $cache whether the individual Responses should be cached.
  *
  * @return void
  * @throws \iveeCrest\Exceptions\IveeCrestException on general CURL error
  */
 public function asyncGetMultiEndpointResponses(array $hrefs, callable $callback, callable $errCallback = null, $accept = null, $cache = true)
 {
     $header = [];
     if (isset($accept)) {
         $header[] = 'Accept: application/' . $accept;
     }
     //run the multi GET
     return $this->cw->asyncMultiGet(array_unique($hrefs), $header, function () {
         return $this->getBearerAuthHeader();
         //little trick to avoid having to make the method public
     }, $callback, $errCallback, $cache);
 }
Beispiel #2
0
 /**
  * Performs parallel asyncronous GET requests to a CREST endpoint. Since the same header is used for all requests,
  * all hrefs passed should be to the same endpoint. This method has void return, instead, responses are
  * passed to the callback functions provided as arguments.
  *
  * This method will most likely be most useful in batch scripting scenarios. If the same data is requested less
  * frequently than the cache TTL, it is advisable to disable caching via argument to avoid overflowing the cache
  * with data that won't be requested again before they expire.
  *
  * @param array $hrefs the hrefs to request
  * @param callable $callback a function expecting one \iveeCrest\Response object as argument, called for every
  * successful response
  * @param callable $errCallback a function expecting one \iveeCrest\Response object as argument, called for every
  * non-successful response
  * @param string $accept the requested representation
  * @param bool $cache whether the individual Responses should be cached.
  *
  * @return void
  * @throws \iveeCrest\Exceptions\IveeCrestException on general CURL error
  */
 public function asyncGetMultiEndpointResponses(array $hrefs, callable $callback, callable $errCallback = null, $accept = null, $cache = true)
 {
     //echo time2s()."cl.asyncGetMultiEndpointResponses()\n";
     $header = array();
     if (isset($accept)) {
         $header[] = 'Accept: application/' . $accept;
     }
     //can't pass "this" in callables
     $client = $this;
     //run the multi GET
     return $this->cw->asyncMultiGet(array_unique($hrefs), $header, function () use($client) {
         return $client->getBearerAuthHeader();
         //little trick to avoid having to make the method public
     }, $callback, $errCallback, $cache);
 }