Skip to content

Commit 7beec07

Browse files
authored
Merge pull request #78 from utopia-php/fix-multicast
Fix multicast
2 parents dcbb18b + dc5b1d8 commit 7beec07

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/Utopia/Messaging/Adapter.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,8 @@ protected function requestMulti(
159159
$urlCount = \count($urls);
160160
$bodyCount = \count($bodies);
161161

162-
if (
163-
$urlCount != $bodyCount &&
164-
($urlCount == 1 && $bodyCount != 1 || $urlCount != 1 && $bodyCount == 1)
165-
) {
166-
throw new \Exception('URL and body counts must be equal or 1.');
162+
if (!($urlCount == $bodyCount || $urlCount == 1 || $bodyCount == 1)) {
163+
throw new \Exception('URL and body counts must be equal or one must equal 1.');
167164
}
168165

169166
if ($urlCount > $bodyCount) {
@@ -172,13 +169,13 @@ protected function requestMulti(
172169
$urls = \array_pad($urls, $bodyCount, $urls[0]);
173170
}
174171

175-
foreach (\array_combine($urls, $bodies) as $url => $body) {
176-
if (!empty($body)) {
177-
$headers[] = 'Content-Length: '.\strlen($body);
172+
for ($i = 0; $i < \count($urls); $i++) {
173+
if (!empty($bodies[$i])) {
174+
$headers[] = 'Content-Length: '.\strlen($bodies[$i]);
178175
}
179176

180-
\curl_setopt($ch, CURLOPT_URL, $url);
181-
\curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
177+
\curl_setopt($ch, CURLOPT_URL, $urls[$i]);
178+
\curl_setopt($ch, CURLOPT_POSTFIELDS, $bodies[$i]);
182179
\curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
183180
\curl_multi_add_handle($mh, \curl_copy_handle($ch));
184181
}

0 commit comments

Comments
 (0)