Dannymh
Active member
Hi all,
With some code that calls API's in my site, I wanted to move to using Guzzle requestAsync instead of request. This is because some of this runs at post time it can cause a delay in the post being completed because of the API requests, so the end user sees the results sometimes after say 15 seconds.
I wanted to see if there was a way to use async so that the request is pushed out but the user making the post doesn't have to wait for the reply to complete their actions as the API calls are external post calls and we don't need the response.
This doesn't seem to be executing and I am not sure why, I am guessing that the $promise procedures are not being seen
With some code that calls API's in my site, I wanted to move to using Guzzle requestAsync instead of request. This is because some of this runs at post time it can cause a delay in the post being completed because of the API requests, so the end user sees the results sometimes after say 15 seconds.
I wanted to see if there was a way to use async so that the request is pushed out but the user making the post doesn't have to wait for the reply to complete their actions as the API calls are external post calls and we don't need the response.
PHP:
$client = \XF::app()->http()->client();
$promise = $client->requestAsync('POST', $options->stcc_apiend."posts", [
'headers' => [
'XF-Api-Key' => $options->stcc_apikey,
'XF-Api-User' => $options->stcc_extuser,
'Accept' => 'application/json'
],
'form_params' => [
'thread_id' => $options->stcc_extthread,
'message' => $newMessage
],
'http_errors' => false
]);
$promise->then(function ($response) {
echo 'Got a response! ' . $response->getStatusCode();
});
This doesn't seem to be executing and I am not sure why, I am guessing that the $promise procedures are not being seen