略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: zookeeper_dispatch

2024-04-30

zookeeper_dispatch

(PECL zookeeper >= 0.4.0)

zookeeper_dispatchCalls callbacks for pending operations

说明

zookeeper_dispatch(): void

The zookeeper_dispatch() function calls the callbacks passwd by operations like Zookeeper::get() or Zookeeper::exists().

警告

Since version 0.4.0, this function must be called manually to achieve asynchronous operations. If you want that to be done automatically, you also can declare ticks at the beginning of your program.

After PHP 7.1, you can ignore this function. This extension uses EG(vm_interrupt) to implement async dispatch.

参数

此函数没有参数。

返回值

没有返回值。

错误/异常

This method emits PHP warning when callback could not be invoked.

范例

示例 #1 zookeeper_dispatch() example #1

Dispatch callbacks manually.

<?php
$client 
= new Zookeeper();
$client->connect('localhost:2181');
$client->get('/zookeeper', function() {
    echo 
"Callback was called".PHP_EOL;
});
while(
true) {
    
sleep(1);
    
zookeeper_dispatch();
}
?>

示例 #2 zookeeper_dispatch() example #2

Declare ticks.

<?php
declare(ticks=1);

$client = new Zookeeper();
$client->connect('localhost:2181');
$client->get('/zookeeper', function() {
    echo 
"Callback was called".PHP_EOL;
});
while(
true) {
    
sleep(1);
}
?>

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/function.zookeeper-dispatch.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3