函数名称:ZMQSocket::send()
适用版本:ZMQExtension >= 1.0.0
函数描述: ZMQSocket::send() 方法用于向指定的 ZeroMQ 套接字发送消息。该方法发送的消息将被传输到与套接字连接的远程端点。
语法: bool ZMQSocket::send(string $message [, int $flags = 0]) : bool
参数:
返回值: 如果消息成功发送,则返回 true。如果发送失败,则返回 false。
示例:
// 创建一个 ZMQ 套接字对象
$context = new ZMQContext();
$socket = $context->getSocket(ZMQ::SOCKET_PUSH);
$socket->connect("tcp://localhost:5555");
// 发送消息到远程端点
$message = "Hello, World!";
if ($socket->send($message)) {
echo "消息发送成功!";
} else {
echo "消息发送失败!";
}
// 使用非阻塞模式发送消息
$message = "Hello, Non-blocking!";
if ($socket->send($message, ZMQ::MODE_NOBLOCK)) {
echo "非阻塞模式消息发送成功!";
} else {
echo "非阻塞模式消息发送失败!";
}
注意事项: