# Send an asynchronous request.
print_r($options);
$request = new \GuzzleHttp\Psr7\Request($method, $uri,$options);
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});` I am not getting the right response with the headers but once i remove the headers i get the response back. Is there something i am missing out. You help will be much appreciated .
Hi. I am attempting to use Guzzle to consume this service: https://github.com/orbitdb/orbit-db-http-api.
However, when passing stream = true to the client get method, I receive the error:
<GET https://localhost:3000/db/my-feed/events/load> [CONNECT]
<GET https://localhost:3000/db/my-feed/events/load> [AUTH_RESULT] severity: "2" message: "HTTP/1.0 403 Forbidden
" message_code: "403"
<GET https://localhost:3000/db/my-feed/events/load> [MIME_TYPE_IS] message: "text/plain"
<GET https://localhost:3000/db/my-feed/events/load> [PROGRESS]
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `GET https://localhost:3000/db/my-feed/events/load` resulted in a `403 Forbidden` response in /home/html/orbitdb/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
However, if I remove stream true, it looks fine (debug=true enabled on request):
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3000 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=AU; ST=A; L=B; O=Organization; OU=OrganizationUnit; CN=localhost; emailAddress=demo@example.com
* start date: May 25 14:56:35 2019 GMT
* expire date: Oct 6 14:56:35 2020 GMT
* common name: localhost (matched)
* issuer: C=AU; ST=A; L=B; O=Internet Widgits Pty Ltd; CN=Local Certificate
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x558b8007c8a0)
> GET /db/zdpuAoZQznotzijaUCrgUEQkPVCH64RCmGHPXUnRPX5EQn3L1%2Fmy-feed2/events/replicate.progress HTTP/2
Host: localhost:3000
Accept: text/event-stream
Cache-Control: no-cache
User-Agent: GuzzleHttp/6.3.3 curl/7.58.0 PHP/7.2.17-0ubuntu0.18.04.1
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
< content-type: text/event-stream; charset=utf-8
< content-encoding: identity
< cache-control: no-cache
< vary: accept-encoding
< date: Sat, 25 May 2019 15:10:38 GMT
But without stream true I can't access the network stream. I'm using a self signed cert but have generated a local CA cert which I have added to the local CA store. curl and guzzle seem to be able to resolve the cert without problem (I'm not disabling it using flags like curl -k).
(new Client())->post('https://example.com‘);
any idea why we are getting this error after the December updates:
[28-Dec-2019 17:57:20 UTC] PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp_idn_uri_convert() in wp-content/plugins/q4vrplugin/vendor/guzzlehttp/guzzle/src/Client.php:220
Stack trace:
#0 guzzlehttp/guzzle/src/Client.php(155): GuzzleHttp\Client->buildUri(Object(GuzzleHttp\Psr7\Uri), Array)
#1 guzzlehttp/guzzle/src/Client.php(183): GuzzleHttp\Client->requestAsync('GET', 'units', Array)
#2 plugin/Models/ApiClient.php(97): GuzzleHttp\Client->request('GET', 'units', Array)
PHP Fatal error: Uncaught Error: Call to undefined method Guzzle\Http\Message\EntityEnclosingRequest::getStatusCode()
$response = $client->post($path, $arr);
$code = $response->getStatusCode();
@oleksandr-roskovynskyi fastest way isn't by using Guzzle, as great as Guzzle actually is.. If absolute maximum speed efficiency is desired, you're best off using an approach utilizing fsockopen and pcntl_fork or similar. Or simply use curl-multi (which Guzzle does too) directly. There's quite a few different approaches to these things, and I think stackoverflow is the best place to find the niche solutions you might look for. It also depends on whether or not your target server is expecting your multitude of connections.. if so, then you can just go nuts and open up 1000 threads. If not, then do keep in mind that webmasters often optimise their setups based on average traffic and your sudden flood of requests could cause problems for them.
If you're set on using Guzzle, the Pool/Batch mode is what you're looking for. Keep in mind though that the result set will grow in memory until all results have been returned. If you want async return, look into using iterators and each_limit.. @alexeyshockov has an awesome code example for that here: https://github.com/alexeyshockov/guzzle-dynamic-pool .. It creates the requests sequentially though, so it's not optimised for speed, but it's still fairly fast once it has opened all the threads it's allowed to.