protected function promiseResponse(Client $client, Request $request, array $options = [])
    {
        // Guzzle Promises do not allow Asynchronous Requests Handling,
        // I have implemented this feature only because it will
        // allow a better Response Time for Paralell Request Handling.
        // This will be implemented in later versions.
        // Because of this, the following snippet will basically work
        // just like a normal Synchronous request, except that the Success
        // and Error callbacks can be configured more conveniently.

        $successCallback = isset($options["onSuccess"]) && is_callable($options["onSuccess"]) ? $options["onSuccess"] : null;
        $errorCallback   = isset($options["onError"]) && is_callable($options["onError"]) ? $options["onError"] : null;
        $cancelCallback  = isset($options["onReject"]) && is_callable($options["onReject"]) ? $options["onReject"] : null;

        $promise = $client->sendAsync($request);
        $promise->then(
            function(ResponseInterface $response)
                use ($successCallback)
            {
                if ($successCallback)
                    return $successCallback($response);

                return $response;
            },
            function(RequestException $exception)
                use ($errorCallback)
            {
                if ($errorCallback)
                    return $errorCallback($exception);

                return $exception;
            }
        );

        if ($cancelCallback) {
            // register promise rejection callback (happens when the
            // cancel() method is called on promises.)
            $promise->otherwise($cancelCallback);
        }

        // Guzzle Promises advantages will only be leveraged
        // in Parelell request execution mode as all requests
        // will be sent in paralell and the handling time goes
        // down to the minimum response time of ALL promises.
        return $promise->wait();
    }
protected function promiseResponse(Client $client, Request $request, array $options = [])
    {
        // Guzzle Promises do not allow Asynchronous Requests Handling,
        // I have implemented this feature only because it will
        // allow a better Response Time for Paralell Request Handling.
        // This will be implemented in later versions.
        // Because of this, the following snippet will basically work
        // just like a normal Synchronous request, except that the Success
        // and Error callbacks can be configured more conveniently.

        $successCallback = isset($options["onSuccess"]) && is_callable($options["onSuccess"]) ? $options["onSuccess"] : null;
        $errorCallback   = isset($options["onError"]) && is_callable($options["onError"]) ? $options["onError"] : null;
        $cancelCallback  = isset($options["onReject"]) && is_callable($options["onReject"]) ? $options["onReject"] : null;

        $promise = $client->sendAsync($request);
        $promise->then(
            function(ResponseInterface $response)
                use ($successCallback)
            {
                if ($successCallback)
                    return $successCallback($response);

                return $response;
            },
            function(RequestException $exception)
                use ($errorCallback)
            {
                if ($errorCallback)
                    return $errorCallback($exception);

                return $exception;
            }
        );

        if ($cancelCallback) {
            // register promise rejection callback (happens when the
            // cancel() method is called on promises.)
            $promise->otherwise($cancelCallback);
        }

        // Guzzle Promises advantages will only be leveraged
        // in Parelell request execution mode as all requests
        // will be sent in paralell and the handling time goes
        // down to the minimum response time of ALL promises.
        return $promise->wait();
    }
protected function promiseResponse ( Client $ client , Request $ request , array $ options = [ ] ) { // Guzzle Promises do not allow Asynchronous Requests Handling, // I have implemented this feature only because it will // allow a better Response Time for Paralell Request Handling. // This will be implemented in later versions. // Because of this, the following snippet will basically work // just like a normal Synchronous request, except that the Success // and Error callbacks can be configured more conveniently. $ successCallback = isset ( $ options [ "onSuccess" ] ) && is_callable ( $ options [ "onSuccess" ] ) ? $ options [ "onSuccess" ] : null ; $ errorCallback = isset ( $ options [ "onError" ] ) && is_callable ( $ options [ "onError" ] ) ? $ options [ "onError" ] : null ; $ cancelCallback = isset ( $ options [ "onReject" ] ) && is_callable ( $ options [ "onReject" ] ) ? $ options [ "onReject" ] : null ; $ promise = $ client -> sendAsync ( $ request ) ; $ promise -> then ( function ( ResponseInterface $ response ) use ( $ successCallback ) { if ( $ successCallback ) return $ successCallback ( $ response ) ; return $ response ; } , function ( RequestException $ exception ) use ( $ errorCallback ) { if ( $ errorCallback ) return $ errorCallback ( $ exception ) ; return $ exception ; } ) ; if ( $ cancelCallback ) { // register promise rejection callback (happens when the // cancel() method is called on promises.) $ promise -> otherwise ( $ cancelCallback ) ; } // Guzzle Promises advantages will only be leveraged // in Parelell request execution mode as all requests // will be sent in paralell and the handling time goes // down to the minimum response time of ALL promises. return $ promise -> wait ( ) ; }
Use GuzzleHTTP Promises v6 Implementation to send
the request asynchronously. As mentioned in the source
code, this method will only leverage the advantages
of Asynchronous execution in later versions.

The current version uses the Promises but will synchronously
execute the Request and wait for it to response.

Configuring the onSuccess, onError and onReject callbacks
is possible using callables. Following signatures will
apply:
- onSuccess: function(ResponseInterface $response)
- onError: function(RequestException $exception)
- onReject: function(string $reason)

@param  Client  $client  [description]
@param  Request $request [description]
@param  array   $options [description]
@return [type]           [description]
Use GuzzleHTTP Promises v6 Implementation to send the request asynchronously . As mentioned in the source code this method will only leverage the advantages of Asynchronous execution in later versions .