From 8e318cd38d76bb1bc6413e067cfc42f96e03aa56 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 14 Feb 2024 18:45:09 +1300 Subject: [PATCH] Fix multicast requests --- src/Utopia/Messaging/Adapter.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Utopia/Messaging/Adapter.php b/src/Utopia/Messaging/Adapter.php index 0e7dc5f..c88301c 100644 --- a/src/Utopia/Messaging/Adapter.php +++ b/src/Utopia/Messaging/Adapter.php @@ -159,11 +159,8 @@ protected function requestMulti( $urlCount = \count($urls); $bodyCount = \count($bodies); - if ( - $urlCount != $bodyCount && - ($urlCount == 1 && $bodyCount != 1 || $urlCount != 1 && $bodyCount == 1) - ) { - throw new \Exception('URL and body counts must be equal or 1.'); + if (!($urlCount == $bodyCount || $urlCount == 1 || $bodyCount == 1)) { + throw new \Exception('URL and body counts must be equal or one must equal 1.'); } if ($urlCount > $bodyCount) { @@ -172,13 +169,13 @@ protected function requestMulti( $urls = \array_pad($urls, $bodyCount, $urls[0]); } - foreach (\array_combine($urls, $bodies) as $url => $body) { - if (!empty($body)) { - $headers[] = 'Content-Length: '.\strlen($body); + for ($i = 0; $i < \count($urls); $i++) { + if (!empty($bodies[$i])) { + $headers[] = 'Content-Length: '.\strlen($bodies[$i]); } - \curl_setopt($ch, CURLOPT_URL, $url); - \curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + \curl_setopt($ch, CURLOPT_URL, $urls[$i]); + \curl_setopt($ch, CURLOPT_POSTFIELDS, $bodies[$i]); \curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); \curl_multi_add_handle($mh, \curl_copy_handle($ch)); }