ChmpxSlave::sendKv
Sends a key and a value message
Description
public function sendKv(string $strbinkey, string $strbinval, bool $is_routing = true, bool $is_broadcast = false): int {}
Sends a key and a value message.
Parameters
- strbinkey
- Specifies key data
- strbinval
- Specifies value data
- is_routing
- Specifies True if sending a message in routing mode
- is_broadcast
- Specifies True if sending a message in broadcasting mode
Return Values
Returns the message length
Examples
php -r '
> $chmpx = new Chmpx();
> $chmpx->CreateServer("./tests/server.yaml", true);
> $svrobj = $chmpx->GetChmpxServer();
> $key = "";
> $val = "";
> $svrobj->receiveKv($key, $val, 10 * 1000, true);
> $svrobj->replyKv($key, $val);'
'
php -r '
> $chmpx = new Chmpx();
> $chmpx->createSlave("./tests/slave.yaml", true);
> echo "isRunning:".$chmpx->isRunning();
> $slaveobj = $chmpx->GetChmpxSlave();
> $key = "hello";
> $val = "world!";
> $slaveobj->sendKv($key, $val, true, false);
> $rkey= "";
> $rval = "";
> sleep(2);
> var_dump($slaveobj->receiveKv($rkey, $rval));
> echo "rkey:".$rkey." rval:".$rval;'
'
The above example will output:
isRunning:1
bool(true)
rkey:hello rval:world!
See Also
- Chmpx::createSlave - Creates a ChmpxSlave instance
- Chmpx::isRunning - Checks if a chmpx process exists
- ChmpxSlave::sendKv - Sends a message with a key and a value
- ChmpxSlave::receiveKv - Receives a message witha a key and a value