thinkphp框架如何开发rpc接口
网站建设技术中使用rpc方式开发应用,会使在网络分布式多程序内的应用程序更加容易。本文分享关于在thinkphp框架中如何开发rpc接口,我们可以通过继承phprpc来实现开发接口以及调用。
推荐学习:mysql视频教程
服务端代码如下:
namespace home\controller;use think\controller\rpccontroller;class servercontroller extends rpccontroller{ protect $allowmethodlist = array('test1','test2'); //表示只允许访问这两个方法 public function test1(){ return 'test1'; } public function test2(){ return 'test2'; } private function test3(){ return 'test3'; } protected function test4(){ return 'test3'; }}
客户端:
namespace home\controller; use think\controller; class indexcontroller extends controller { public function index(){ vendor('phprpc.phprpc_client'); $client = new \phprpc_client('http://servername/index.php/home/server'); // 或者采用 //$client = new \phprpc_client(); //$client->useservice('http://servername/index.php/home/server'); //调用服务端方法 $result = $client->test1(); } }
更多网站建设教程,请关注!
以上就是thinkphp框架如何开发rpc接口的详细内容。