Asynchronous API call to self in symfony 3 / php / guzzle

Active3 hr before
Viewed126 times

6 Answers


Main problem of comments above: they missed event loop part. From guzzle side there is problem too - it should call $curl->tick itself inside of $query->run() to hide implementation details (there are other backends except curl!). But that has nothing to do with async question.,But $curl->tick() calls \GuzzleHttp\Promise\queue()->run() inside! And it use delays inside, so yes, @natebrunette, it's blocking but not for long, request itself is much longer.,To wait for all requests to complete you can use this from the mentioned example:,What a bullshit that asynchronous requests feature! Does not seem to work at all :(. In this example, the callbacks are never executed unless you uncomment the wait() (which of course is not what we want to do):

$req = $client - > getAsync(''); // Shouldn't request be sent here ? ...

// do something while the long request is in progress in order not to waste time

$req - > then(...);
$req - > wait(); // ... so here request can already complete
load more v

The HTTP client is interoperable with many common HTTP client abstractions in PHP. You can also use any of these abstractions to profit from autowirings. See Interoperability for more information.,The HttpClient component is a low-level HTTP client with support for both PHP stream wrappers and cURL. It provides utilities to consume APIs and supports synchronous and asynchronous operations. You can install it with:,This component also supports streaming responses for full asynchronous applications.,The following standalone example demonstrates a way to use the HTTP client and test it in a real application:

$ composer require symfony / http - client
load more v

protocols: (array, default=['http', 'https']) Specified which protocols are allowed for redirect requests.,protocols: (array, default=['http', 'https']) Specified which protocols are allowed for redirect requests. ,Pass a string to specify an HTTP proxy, or an array to specify different proxies for different protocols.,on_redirect: (callable) PHP callable that is invoked when a redirect is encountered. The callable is invoked with the original request and the redirect response that was received. Any return value from the on_redirect function is ignored.

$client = new GuzzleHttp\ Client(['base_uri' => '']);
load more v

On the flip side, they don’t have as intuitive an interface, nor the helper utility methods that third-party libraries such as GuzzleHttp and Symfony’s HTTP client, do. In addition, it:,Created by Michael Dowling, GuzzleHttp is likely the most well-known and used of the three third-party libraries that I’m covering in this tutorial.,Symfony’s HTTP client,Now that we’ve looked at two native ways to make HTTP/S requests in PHP, let’s see how to do so using three of the most well-known third-party packages.

mkdir - p php - http / photos
cd php - http
composer require vlucas / phpdotenv
load more v

Guzzle can send both synchronous and asynchronous requests.,If you are familiar with Rest API, you must know about HTTP calls created for getting and posting data from the client to the server. What if you wish to create a REST API client in PHP? Your answer would be to go with CURL. CURL is the most widely used method to make HTTP calls but it contains several complicated steps.,Let’s see how Guzzle creates a request:,So all my servers hosted on the Cloudways Platforms are being fetched. Similarly, you can create new methods with HTTP calls to get applications, server settings, services and etc.

$url = “https: //”
load more v

Search Answer Titles

$response = $client - > request('POST', '', [
   'form_params' => [
      'field_name' => 'abc',
      'other_field' => '123',
      'nested_field' => [
         'nested' => 'hello'

Other "undefined-undefined" queries related to "Asynchronous API call to self in symfony 3 / php / guzzle"