Home > PHP Framework > ThinkPHP > How the ThinkPHP framework develops RPC interfaces

How the ThinkPHP framework develops RPC interfaces

angryTom
Release: 2020-03-14 10:03:17
forward
5576 people have browsed it

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 the ThinkPHP framework develops RPC interfaces

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';
   }
}
Copy after login

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();
 
    }
 
}
Copy after login

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!

Related labels:
source:www.yidianphp.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template