ZMQContext::getSocket
Create a new socket
説明
public ZMQSocket ZMQContext::getSocket(int $type
, string $persistent_id
= null
, callable $on_new_socket
= null
)
パラメータ
-
type
-
ZMQ::SOCKET_*
constant to specify socket type.
-
persistent_id
-
If persistent_id
is specified the socket will be persisted over multiple requests.
-
on_new_socket
-
Callback function, which is executed when a new socket structure is created. This function does not get invoked
if the underlying persistent connection is re-used. The callback takes ZMQSocket and persistent_id as two arguments.
戻り値
Returns a ZMQSocket object.
エラー / 例外
Throws ZMQSocketException on error.
例
例1 A ZMQContext example
<?php
/* Allocate a new context */
$context = new ZMQContext();
/* Create a new socket */
$socket = $context->getSocket(ZMQ::SOCKET_REQ, 'my sock');
/* Connect the socket */
$socket->connect("tcp://example.com:1234");
/* Send a request */
$socket->send("Hello there");
/* Receive back the response */
$message = $socket->recv();
echo "Received message: {$message}\n";
?>