What is rpc? What are the popular rpc frameworks in php.

Source: Internet
Author: User
Tags zts
What is rpc? What are the popular rpc frameworks in php. Better layout: www. zybuluo. comphpernote76641 what is the rpc framework? answer the first question: what is the RPC framework? In one sentence, RPC is called RemoteProcedureCall. What is remote call? Normally we call

What is rpc? What are the popular rpc frameworks in php. Better layout: https://www.zybuluo.com/phper/note/76641 what is the rpc framework first answer the first question: what is the RPC framework? In one sentence, RPC is: Remote Procedure Call. What is Remote Call? Normally we call






What is rpc? What are the popular rpc frameworks in php.

Better typographical: https://www.zybuluo.com/phper/note/76641

What is an rpc framework?

Answer the first question:What is an RPC framework?? RPC is the Remote Procedure Call framework)

What isRemote Call?

Generally, we call a method in php, such as a function method: localAdd (10, 20). The specific implementation of the localAdd method is either defined by the user, it is either self-contained in the php library function, that is, the code of the localAdd method is implemented locally, and it is a local call!

Remote CallIndicates the specific implementation of the called method.NoThe program runs locally, but somewhere else.

Remote Call Principle

For example, A (client) callsremoteAddMethod:

  1. First, establish a tcp connection between A and B;

  2. Then A serializes the name of the method to be called (remoteAdd here) and the method parameter (10, 20) into the word throttling and sends it out;

  3. B accepts the byte stream sent by A and deserializes it to obtain the target method name and method parameter. Then, execute the corresponding method call (probably localAdd) and return the result 30;

  4. A accepts the remote call result and outputs 30.

The RPC framework encapsulates the details I have just mentioned and exposes simple and friendly APIs to users.

Benefits of remote calls

Decoupling: when the server needs to implement modifications within the method, the client is completely unaware of the changes and does not need to make any changes. This method is often used in cross-department and cross-company cooperation, in addition, the method provider is usually called service exposure.

What is the difference between RPC and Socket?

Through the above simple explanation, it seems like RPC and Socket. They all call remote methods in client/server mode. I also wrote an article about socket. What are their differences?

RPC (Remote process call) implements communication between two processes in the Client/Server mode. Socket is one of the commonly used communication methods of RPC. RPC is implemented based on Socket, which requires more network and system resources than socket. In addition to Socket and RPC, there are other communication methods, such as http and the pipeline that comes with the operating system, to call remote programs. In Microsoft Windows, RPC uses Named Pipes for communication.

What is the difference between RPC and REST?

After understanding RPC, we know that RPC is in the client/server mode. Calling remote methods and REST are also a set of API call protocol methods that we are familiar, it is also based on the client/server mode and calls remote methods. What are the differences between them?

Both rest api and RPC are inServerEncapsulate functions as interfaces for exposureClientBut the rest api is based onHTTP protocolREST is committed to providing an http request through POST/GET/PUT/DELETE methods in the http protocol and a readable URL. RPC is not based on the HTTP protocol.
Therefore, if two backend languages call each other, RPC can provide better performance (eliminating the need for HTTP headers and other things), and configuration should be easier. If the frontend calls the backend through AJAX, it is better to use the rest api form (because HTTP cannot be avoided in any case ).

What are the popular rpc frameworks in php?

Since php is the best language in the world, what are the popular RPC frameworks in php?

First, list phprpc, yar, thrift, gRPC, swoole, and hprose.

Because of the limited time and energy, it is impossible to learn and use them one by one. Let me select the most useful ones in the world. Because RPC works in the same principle, it is in Client/Server mode, but the usage of each framework is different.

I have heard about phprpc and yar most recently.

Phprpc

Download the latest stable version of phprpc from the official website: Download the link and unzip it.

Install

We will find that there are many files and folders in the structure as follows:

  • Dhparams/
  • Pecl/
  • Bigint. php
  • Compat. php
  • Phprpc_date.php
  • Xxtea. php
  • Dhparams. php
  • Phprpc_server.php
  • Phprpc_client.php

Among them, dhparams and pecl are folders, and pecl is the xxtea extension of php. According to the description on the official website, they can be installed or not installed, and phprpc can also be run without installation. But if you need faster encryption processing, you can install it.

Install it. After all, faster encryption is a good thing:

The installation procedure is as follows. Copy the xxtea folder under pecl to the etx directory of the php source code:/lamp/php-5.4.11/ext. Then use phpize for extension and re-compile.

 

 
  1. [root@localhost /]# cd /lamp/php-5.4.11/ext/xxtea
  2. [root@localhost xxtea]#/usr/local/php/bin/phpize
  3. [root@localhost xxtea]#./configure --enable-xxtea=shared --with-php-config=/usr/local/php/bin/php-config
  4. make && make install

OK. The compilation is complete. The prompt "xxtea. so" is already in/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xxtea.so.

Next, we need to add xxtea. so at the end of php. ini:

[root@localhost /]# vi /usr/local/php/etc/php.ini [xxtea]extension=xxtea.so

Okay. After the installation, We need to restart apache or php-fpm.

Restart apache [root @ localhost/] #/usr/local/apache/bin/apachectl restart to smoothly restart php-fpmkill-USR2 'cat/usr/local/php/var/run/ php-fpm.pid'

After the restart, open the phpinfo () page and search for it to see the xxtea page.

Start to use

Let's take a simple example. phprpc is also divided into server and client. Therefore, phprpc_server.php and phprpc_client.php are matched in the folder.

Let's take a few examples on the official website and practice:

server.phpServer: This completes the simplest helloword interface.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.