Skip to content

Commit

Permalink
Support batch api method (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
everlCode authored Oct 16, 2024
1 parent 8d81584 commit 03be8f3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ public function info()
return $this->send('info');
}

/**
* Sending many commands in one request
*
* @param array $data
* @return mixed
*/
public function batch(array $data)
{
return $this->send('batch', $data);
}

/**
* Generate connection JWT. See https://centrifugal.dev/docs/server/authentication.
* Keep in mind that this method does not support all claims of Centrifugo JWT connection
Expand Down
28 changes: 27 additions & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ public function testPublishNetworkError()
{
$this->expectException(Exception::class);
$client = new \phpcent\Client("http://localhost:9000/api");
$res = $client->publish('channel', ["message" => "Hello World"]);

$client->setConnectTimeoutOption(5);
$client->setTimeoutOption(15);

$client->publish('channel', ["message" => "Hello World"]);
}

public function testInfo()
Expand All @@ -77,4 +81,26 @@ public function testInfo()
$this->assertNotNull($res);
$this->assertTrue(is_array($res->result->nodes));
}

public function testBatch()
{
$data = [
"commands" => [
[
"presence_stats" => [
"channel" => "test1"
]
],
[
"publish" => [
"channel" => "x:test2",
"data" => []
]
]
]
];

$res = $this->client->batch($data);
$this->assertIsArray($res->replies);
}
}

0 comments on commit 03be8f3

Please sign in to comment.