0MQ messaging ZMQContext::getSocket
(PECL zmq >= 0.5.0)
ZMQContext::getSocket — 새 소켓 만들기
설명
public ZMQContext::getSocket(int $type
, string $persistent_id
= null
, callable $on_new_socket
= null
): ZMQSocket
컨텍스트에서 새 소켓을 생성하기 위한 바로 가기입니다. 컨텍스트가 영속적이지 않으면 Persistent_id
매개변수가 무시되고 소켓이 비영구 상태로 대체됩니다. on_new_socket
은 새로운 기본 소켓 구조가 생성될 때만 호출됩니다.
매개변수
type
ZMQ::SOCKET_*
소켓 유형을 지정하는 상수입니다.persistent_id
persistent_id
가 지정되면 소켓은 여러 요청에 대해 지속됩니다.on_new_socket
- 새로운 소켓 구조가 생성될 때 실행되는 콜백 함수. 기본 지속 연결이 재사용되는 경우 이 함수가 호출되지 않습니다. 콜백은 ZMQSocket과 persistent_id를 두 개의 인수로 사용합니다.
반환 값
ZMQSocket 객체를 반환합니다.
오류/예외
오류가 발생하면 ZMQSocketException을 던집니다.
Examples
예제 #1 ZMQContext() 예제
기본 사용법
<?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";
?>