服务端代码
/***
* 远程 prc 入口
* @name clsApi
*
*/
class clsApi
{
/**
* @param string $product
* @param $data
*/
public function api(string $product = '',$data){
}
}
$service_api = new Yar_Server(new clsApi());
$service_api->handle();
?>
客户端代码实现
<?php
/**
*
* @name clsClient
*/
class clsClient
{
/***
* rpc 远程 调用
* @param $api_name string
* @param array $data
* @param $products
* @param $method
* @return mixed
*/
public static function rpcApi($api_name,array $data = [],$products,$method): mixed
{
$api_url = clsDirsENV::YCKJ_HOST.$api_name;
$client = new Yar_Client($api_url);
$result = $client->$method($products,$data);
return $result;
}
}