Home>Article>PHP Framework> How the ThinkPHP framework develops RPC interfaces
This article introduces how to use the ThinkPHP framework to develop RPC interfaces. It has certain reference value. I hope it will be helpful to friends who are learning thinkPHP!
How does ThinkPHP framework develop RPC interface
Using RPC method to develop applications in website construction technology will make the network more distributed. In-app applications are even easier. This article shares how to develop RPC interfaces in the ThinkPHP framework. We can implement development interfaces and calls by inheriting PHPRpc.
Recommended learning:MySQL video tutorial
The server code is as follows:
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'; } }
Client:
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(); } }
Morewebsite construction tutorial, please pay attention to the PHP Chinese website!
The above is the detailed content of How the ThinkPHP framework develops RPC interfaces. For more information, please follow other related articles on the PHP Chinese website!