php - GuzzleHttps - How to send async. data via POST (using Pool) -
i'm trying send post data via pool in guzzle library. but, @ address data sending post empty - don't it.
$client = new client(); $requests = function () { foreach($this->urls $url) { yield new request('post', $url, [ 'body' => '...' ]); } };
i tried form_params , multiparts, not working again (post empty again $_request & $_get).
and of course piece of code (for completeness):
$pool = new pool($client, $requests(), [ 'concurrency' => count($this->urls), 'fulfilled' => function ($response) {}, 'rejected' => function ($reason) {}, }); $promise = $pool->promise(); $promise->wait();
guzzle sends request correctly (enter on second server), in not have data.
what doing wrong? thanks!
edit:
i'm trying replace code guzzle (is repeated in cycle now):
$ch = curl_init(); $url = 'https://example.cop'; curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_ssl_verifypeer, false); curl_setopt($ch, curlopt_useragent, 'mehehe_net'); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_nosignal, 1); curl_setopt($ch, curlopt_timeout_ms, 59000); curl_setopt($ch, curlopt_post, true); $dt = ["data" => json_encode($queue)]; curl_setopt($ch, curlopt_postfields, $dt); curl_setopt($ch, curlopt_verbose, true); $cont = curl_exec($ch); curl_close($ch);
this solution working great! :-)
$pss = []; $client = new client(); $uri = "https://example.com"; foreach($data $alarm) { $pss[] = $client->postasync($uri, ['form_params' => ["alarms" => json_encode($alarm)]])->then(function ($response) use ($alarm) { // $response->getbody(); }); } \guzzlehttp\promise\unwrap($permis);
do not forget use unwrap (wait) after loop! :-)
Comments
Post a Comment