|
本地的server说明:
server url地址 http://other.program.php/php-library/source/yar/model/yar_server.php
sever代码:
$server = new Yar_Server(new MyYarServer());
$server->handle();
client url地址:http://other.program.php/php-library/source/yar/pc_yar.php
client代码:
$pc_client = new Yar_Client($server_url);
$id = 12;
//就像调用本地方法一样
$pc_client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, 1000);
$res = $pc_client->getData($id);
print_r($res);
client的并行调用,是采用curl的方式实现的
function callback($retval, $callinfo) {
var_dump($retval,$callinfo);
}
function error_callback($type, $error, $callinfo) {
error_log($error);
}
$server_url = "http://other.program.php/php-library/source/yar/model/yar_server.php";
Yar_Concurrent_Client::call($server_url, "getData", array("1"), "callback");
Yar_Concurrent_Client::call($server_url, "getData", array("2"));// if the callback is not specificed,
// callback in loop will be used
Yar_Concurrent_Client::call($server_url, "getData", array("3"), "callback", NULL, array(YAR_OPT_PACKAGER => "json"));
//this server accept json packager
Yar_Concurrent_Client::call($server_url, "getData", array("11"), "callback", NULL, array(YAR_OPT_TIMEOUT=>1));
Yar_Concurrent_Client::loop("callback","error_callback");
|
|
|