每個服務(wù)器上都安裝yar擴(kuò)展
然后要被訪問的服務(wù)器上寫一段代碼,開啟rpc 服務(wù)器
index控制器index方法里:
~~~
if($_SERVER['PHP_SELF'] == '/nmp_remote.php'){
$this->yar();
return '';
}
public function yar(){
? ? ? ? $server = new \Yar_Server(new YarApi);
? ? ? ? return $server->handle();
}
~~~
~~~
namespace app\common\lib;
Class YarApi{
/**
* 調(diào)用內(nèi)部函數(shù)
* @param? string $name? ?函數(shù)名
* @param? array? $params 參數(shù) 沒有傳[]
* @return mixed? ? ? ? ?返回結(jié)果
*/
public function function_call($name, $params=[]){
if(function_exists($name)){
return call_user_func_array($name, $params);
}else{
return 'function not exists';
}
}
/**
* 調(diào)用類方法
* @param? string $className 類命名空間
* @param? string $method? ? 方法名
* @param? array? $params? ? 參數(shù) 沒有傳[]
* @return mixed? ? ? ? ? ? 返回結(jié)果
*/
public function class_call($className, $method, $params=[]){
if(method_exists($className, $method)){
return call_user_func_array([$className, $method], $params);
}else{
return 'method not exists';
}
}
}
~~~
暴露的是 server里傳入的類 的方法
這兩個方法其實(shí)用于調(diào)用函數(shù)和類方法 、 類方法支持靜態(tài)。
然后 其他模塊里訪問:
~~~
$client = new \yar_client("http://nmp.cn/nmp_remote.php");
$ret = $client->function_call('build_part_commission_table', [['user_id'=>1, 'finish_time'=>'2017-10-28 10:00:00']]);
$data = [];
$ret2 = $client->class_call('\aa', 'sel', ['a']);
}
~~~

暴露的是 server里傳入的類 的方法
這兩個方法其實(shí)用于調(diào)用函數(shù)和類方法 、 類方法支持靜態(tài)。
然后 其他模塊里訪問:
~~~
$client = new \yar_client("http://nmp.cn/nmp_remote.php");
$ret = $client->function_call('build_part_commission_table', [['user_id'=>1, 'finish_time'=>'2017-10-28 10:00:00']]);
$data = [];
$ret2 = $client->class_call('\aa', 'sel', ['a']);
~~~
- 序
- 前端
- 通用
- bootstrap
- angular
- ui-router
- controller
- react
- 后端
- php
- mysql
- 自定義函數(shù)
- 運(yùn)維
- appveyor ci構(gòu)建php擴(kuò)展
- api
- weixin
- geo
- 西陸整理
- 人員
- 目錄結(jié)構(gòu)
- 數(shù)據(jù)庫結(jié)構(gòu)
- 項(xiàng)目初始化
- 小記憶
- 分頁函數(shù)
- 系統(tǒng)函數(shù)庫
- 常用函數(shù)庫
- 操作數(shù)據(jù)庫
- 幫助演示
- ct高級搜索
- 測試代碼極客tags
- 服務(wù)器
- java
- yar
- 簡歷
- tcp
- efi分區(qū)加載
- 氧庫測試
- 測試
- pgsql
- 轉(zhuǎn)換
