array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'zmqcontext.getsocket.php', 1 => 'ZMQContext::getSocket', ), 'up' => array ( 0 => 'class.zmqcontext.php', 1 => 'ZMQContext', ), 'prev' => array ( 0 => 'zmqcontext.getopt.php', 1 => 'ZMQContext::getOpt', ), 'next' => array ( 0 => 'zmqcontext.ispersistent.php', 1 => 'ZMQContext::isPersistent', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/zmq/zmqcontext/getsocket.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PECL zmq >= 0.5.0)
ZMQContext::getSocket — Create a new socket
$type
, string $persistent_id
= null
, callable $on_new_socket
= null
): ZMQSocket
Shortcut for creating new sockets from the context. If the context is not persistent the persistent_id
parameter is ignored and the socket falls back to being non-persistent. The on_new_socket
is called only
when a new underlying socket structure is created.
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.
Örnek 1 A ZMQContext() example
Basic usage
<?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";
?>