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:
First, establish a tcp connection between A and B;
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;
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;
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.
Download the latest stable version of phprpc from the official website: Download the link and unzip it.
We will find that there are many files and folders in the structure as follows:
- Bigint. php
- Compat. php
- Xxtea. php
- Dhparams. 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.
- [root@localhost /]# cd /lamp/php-5.4.11/ext/xxtea
- [root@localhost xxtea]#/usr/local/php/bin/phpize
- [root@localhost xxtea]#./configure --enable-xxtea=shared --with-php-config=/usr/local/php/bin/php-config
- 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.