GuzzleHttp\Client::sendAsync PHP Method

sendAsync() public method

public sendAsync ( Psr\Http\Message\RequestInterface $request, array $options = [] )
$request Psr\Http\Message\RequestInterface
$options array
    public function sendAsync(RequestInterface $request, array $options = [])
    {
        // Merge the base URI into the request URI if needed.
        $options = $this->prepareDefaults($options);
        return $this->transfer($request->withUri($this->buildUri($request->getUri(), $options), $request->hasHeader('Host')), $options);
    }

Usage Example

 /**
  * @param RequestInterface       $request
  * @param CacheStrategyInterface $cacheStorage
  * @param CacheEntry             $cacheEntry
  *
  * @return bool if added
  */
 protected function addReValidationRequest(RequestInterface $request, CacheStrategyInterface &$cacheStorage, CacheEntry $cacheEntry)
 {
     // Add the promise for revalidate
     if ($this->client !== null) {
         /** @var RequestInterface $request */
         $request = $request->withHeader(self::HEADER_RE_VALIDATION, '1');
         $this->waitingRevalidate[] = $this->client->sendAsync($request)->then(function (ResponseInterface $response) use($request, &$cacheStorage, $cacheEntry) {
             $update = false;
             if ($response->getStatusCode() == 304) {
                 // Not modified => cache entry is re-validate
                 /** @var ResponseInterface $response */
                 $response = $response->withStatus($cacheEntry->getResponse()->getStatusCode());
                 $response = $response->withBody($cacheEntry->getResponse()->getBody());
                 // Merge headers of the "304 Not Modified" and the cache entry
                 foreach ($cacheEntry->getResponse()->getHeaders() as $headerName => $headerValue) {
                     if (!$response->hasHeader($headerName)) {
                         $response = $response->withHeader($headerName, $headerValue);
                     }
                 }
                 $update = true;
             }
             self::addToCache($cacheStorage, $request, $response, $update);
         });
         return true;
     }
     return false;
 }
All Usage Examples Of GuzzleHttp\Client::sendAsync