From ce75237d143e89af5d8f9cfee4d7ef28951b0f81 Mon Sep 17 00:00:00 2001 From: "Melvin D. Protacio" Date: Tue, 13 Aug 2024 07:20:47 +0800 Subject: [PATCH 1/3] request asynchronously to avoid performance penalty when sending impressions --- src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php b/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php index b5b4b7c3..af819f02 100644 --- a/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php +++ b/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php @@ -50,6 +50,6 @@ public function dispatchEvent(LogEvent $event) 'connect_timeout' => DefaultEventDispatcher::TIMEOUT ]; - $this->httpClient->request($event->getHttpVerb(), $event->getUrl(), $options); + $this->httpClient->requestAsync($event->getHttpVerb(), $event->getUrl(), $options); } } From a4107ad881b316fabe92a0ba32c10a22986704ca Mon Sep 17 00:00:00 2001 From: "Melvin D. Protacio" Date: Tue, 13 Aug 2024 07:30:08 +0800 Subject: [PATCH 2/3] update test to use asynchronous request --- tests/EventTests/DefaultEventDispatcherTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/EventTests/DefaultEventDispatcherTest.php b/tests/EventTests/DefaultEventDispatcherTest.php index 9b138ce3..960ec1c7 100644 --- a/tests/EventTests/DefaultEventDispatcherTest.php +++ b/tests/EventTests/DefaultEventDispatcherTest.php @@ -49,7 +49,7 @@ public function testDispatchEvent() ->getMock(); $guzzleClientMock->expects($this->once()) - ->method('request') + ->method('requestAsync') ->with($logEvent->getHttpVerb(), $logEvent->getUrl(), $expectedOptions); $eventDispatcher = new DefaultEventDispatcher($guzzleClientMock); From 873a824832a0aa0ee350c29a216b48942b6e7eb4 Mon Sep 17 00:00:00 2001 From: "Melvin D. Protacio" Date: Tue, 13 Aug 2024 08:59:46 +0800 Subject: [PATCH 3/3] add promise resolution to actually invoke the call --- src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php b/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php index af819f02..5dcf86b0 100644 --- a/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php +++ b/src/Optimizely/Event/Dispatcher/DefaultEventDispatcher.php @@ -50,6 +50,7 @@ public function dispatchEvent(LogEvent $event) 'connect_timeout' => DefaultEventDispatcher::TIMEOUT ]; - $this->httpClient->requestAsync($event->getHttpVerb(), $event->getUrl(), $options); + $this->httpClient->requestAsync($event->getHttpVerb(), $event->getUrl(), $options) + ->then(fn($response) => $response); } }