(PECL yar >= 1.0.0)
Yar_Concurrent_Client::loop — 锟斤拷锟斤拷锟斤拷锟斤拷注锟斤拷牟锟斤拷械锟斤拷锟�
$callback
[, callable $error_callback
]] ) : boolean锟斤拷锟斤拷锟斤拷锟叫碉拷锟窖撅拷通锟斤拷 Yar_Concurrent_Client::call()注锟斤拷牟锟斤拷械锟斤拷锟�, 锟斤拷锟揭等达拷锟斤拷锟斤拷.
callback
锟斤拷锟斤拷锟斤拷锟截碉拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷, 锟斤拷么Yar锟节凤拷锟酵筹拷锟斤拷锟叫碉拷锟斤拷锟斤拷之锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷氐锟斤拷锟斤拷锟�(锟斤拷时锟斤拷没锟斤拷锟轿猴拷锟斤拷锟襟返伙拷), 锟斤拷锟矫碉拷时锟斤拷$callinfo锟斤拷锟斤拷锟斤拷NULL.
锟斤拷锟斤拷锟阶拷岵拷械锟斤拷玫锟绞憋拷锟斤拷贫锟斤拷锟絚allback, 锟斤拷么锟角革拷callback锟叫革拷锟竭碉拷锟斤拷锟饺硷拷.
error_callback
锟斤拷锟斤拷氐锟斤拷锟斤拷锟�, 锟斤拷锟斤拷锟斤拷锟斤拷锟�, 锟斤拷么Yar锟节筹拷锟斤拷锟绞憋拷锟斤拷锟斤拷锟斤拷锟斤拷锟截碉拷锟斤拷锟斤拷.
Example #1 Yar_Concurrent_Client::loop() example
<?php
function callback($retval, $callinfo) {
if ($callinfo == NULL) {
echo "锟斤拷锟斤拷, 锟斤拷锟叫碉拷锟斤拷锟襟都凤拷锟斤拷去锟斤拷, 锟斤拷没锟斤拷锟轿猴拷锟斤拷锟襟返伙拷\n";
} else {
echo "锟斤拷锟斤拷一锟斤拷远锟教碉拷锟矫的凤拷锟斤拷, 锟斤拷锟矫的凤拷锟斤拷锟斤拷锟斤拷", $callinfo["method"],
". 锟斤拷锟矫碉拷sequence锟斤拷 " , $callinfo["sequence"] , "\n";
var_dump($retval);
}
}
function error_callback($type, $error, $callinfo) {
error_log($error);
}
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback");
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters")); // if the callback is not specificed,
// callback in loop will be used
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_PACKAGER => "json"));
//this server accept json packager
Yar_Concurrent_Client::call("http://host/api/", "some_method", array("parameters"), "callback", NULL, array(YAR_OPT_TIMEOUT=>1));
//custom timeout
Yar_Concurrent_Client::loop("callback", "error_callback"); //send the requests,
//the error_callback is optional
?>
锟斤拷锟斤拷锟斤拷锟教碉拷锟斤拷锟斤拷锟斤拷锟斤拷冢锟�
锟斤拷锟斤拷, 锟斤拷锟叫碉拷锟斤拷锟襟都凤拷锟斤拷去锟斤拷, 锟斤拷没锟斤拷锟轿猴拷锟斤拷锟襟返伙拷 锟斤拷锟斤拷一锟斤拷远锟教碉拷锟矫的凤拷锟斤拷, 锟斤拷锟矫的凤拷锟斤拷锟斤拷锟斤拷some_method, 锟斤拷锟矫碉拷sequence锟斤拷 4 string(11) "some_method" 锟斤拷锟斤拷一锟斤拷远锟教碉拷锟矫的凤拷锟斤拷, 锟斤拷锟矫的凤拷锟斤拷锟斤拷锟斤拷some_method, 锟斤拷锟矫碉拷sequence锟斤拷 1 string(11) "some_method" 锟斤拷锟斤拷一锟斤拷远锟教碉拷锟矫的凤拷锟斤拷, 锟斤拷锟矫的凤拷锟斤拷锟斤拷锟斤拷some_method, 锟斤拷锟矫碉拷sequence锟斤拷 2 string(11) "some_method" 锟斤拷锟斤拷一锟斤拷远锟教碉拷锟矫的凤拷锟斤拷, 锟斤拷锟矫的凤拷锟斤拷锟斤拷锟斤拷some_method, 锟斤拷锟矫碉拷sequence锟斤拷 3 string(11) "some_method"