Skip to content

Commit

Permalink
Merge pull request #78 from utopia-php/fix-multicast
Browse files Browse the repository at this point in the history
Fix multicast
  • Loading branch information
abnegate authored Feb 15, 2024
2 parents dcbb18b + dc5b1d8 commit 7beec07
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Utopia/Messaging/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
}
Expand Down

0 comments on commit 7beec07

Please sign in to comment.