PHP.mk документација

ZMQPoll::poll

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

zmqpoll.poll.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека zmqpoll.poll.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ZMQPoll::poll

Референца за `zmqpoll.poll.php` со подобрена типографија и навигација.

zmqpoll.poll.php

ZMQPoll::poll

Класата ZMQ

ZMQPoll::pollPoll the items

= NULL

public ZMQPoll::poll(array &$readable, array &$writable, int $timeout = -1): int

Polls the items in the current poll set. The readable and writable items are returned in the readable and writable parameters. ZMQPoll::getLastErrors() can be used to check if there were errors.

Параметри

readable

Array where readable ZMQSockets/PHP streams are returned. The array will be cleared at the beginning of the operation.

writable

Array where writable ZMQSockets/PHP streams are returned. The array will be cleared at the beginning of the operation.

timeout

Timeout for the operation. -1 means that poll waits until at least one item has activity. Please note that starting from version 1.0.0 the poll timeout is defined in milliseconds, rather than microseconds.

Вратени вредности

Returns an integer representing the amount of items with activity.

Errors/Exceptions

). Ако повикот не успее, ќе врати ZMQPollException при грешка.

Примери

ако е овозможен колекторот за отпадоци, ZMQPoll() example

Create a simple poll server

<?php

/* Create socket, request-reply pattern (reply socket) */
$context = new ZMQContext();
$server = $context->getSocket(ZMQ::SOCKET_REP);

/* Bind to port 5555 on 127.0.0.1 */
$server->bind("tcp://127.0.0.1:5555");

/* Create new pollset for incoming/outgoing message */
$poll = new ZMQPoll();

/* Add the object and listen for poll in/out */
$id = $poll->add($server, ZMQ::POLL_IN | ZMQ::POLL_OUT);
echo
"Added object with id " . $id . "\n";

/* Initialise readable and writable arrays */
$readable = array();
$writable = array();

while (
true) {
/* Amount of events retrieved */
$events = 0;

try {
/* Poll until there is something to do */
$events = $poll->poll($readable, $writable, -1);
$errors = $poll->getLastErrors();

if (
count($errors) > 0) {
foreach (
$errors as $error) {
echo
"Error polling object " . $error . "\n";
}
}
} catch (
ZMQPollException $e) {
echo
"poll failed: " . $e->getMessage() . "\n";
}

if (
$events > 0) {
/* Loop through readable objects and recv messages */
foreach ($readable as $r) {
try {
echo
"Received message: " . $r->recv() . "\n";
} catch (
ZMQException $e) {
echo
"recv failed: " . $e->getMessage() . "\n";
}
}

/* Loop through writable and send back messages */
foreach ($writable as $w) {
try {
$w->send("Got it!");
} catch (
ZMQException $e) {
echo
"send failed: " . $e->getMessage() . "\n";
}
}
}
}
?>

Белешки од корисници

Нема белешки од корисници за оваа страница.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.