GuzzleHttp\Client::requestAsync PHP Method

requestAsync() public method

public requestAsync ( $method, $uri = '', array $options = [] )
$options array
    public function requestAsync($method, $uri = '', array $options = [])
    {
        $options = $this->prepareDefaults($options);
        // Remove request modifying parameter because it can be done up-front.
        $headers = isset($options['headers']) ? $options['headers'] : [];
        $body = isset($options['body']) ? $options['body'] : null;
        $version = isset($options['version']) ? $options['version'] : '1.1';
        // Merge the URI into the base URI.
        $uri = $this->buildUri($uri, $options);
        if (is_array($body)) {
            $this->invalidBody();
        }
        $request = new Psr7\Request($method, $uri, $headers, $body, $version);
        // Remove the option so that they are not doubly-applied.
        unset($options['headers'], $options['body'], $options['version']);
        return $this->transfer($request, $options);
    }

Usage Example

Example #1
1
 /**
  * Return a promise for async requests.
  *
  * @param string $method
  * @param string $url
  * @param array  $body
  * @param array  $query
  * @param array  $headers
  *
  * @return \GuzzleHttp\Promise\PromiseInterface
  */
 public function requestAsync($method, $url, $body = [], $query = [], $headers = [])
 {
     if (!empty($body)) {
         $body = encode($body);
         $headers['Content-Type'] = 'application/json';
     } else {
         $body = null;
     }
     $headers = array_merge($this->global_headers, $headers);
     return $this->client->requestAsync($method, $url, ['query' => $query, 'body' => $body, 'headers' => $headers]);
 }
All Usage Examples Of GuzzleHttp\Client::requestAsync