A simple introduction to using XML-RPC to construct Web Service in PHP_PHP Tutorial

WBOY
Release: 2016-07-15 13:26:05
Original
918 people have browsed it

There are currently two protocol standards for Web Service communication, one is XML-RPC and the other is SOAP. XML-RPC is relatively simple and appeared earlier, while SOAP is more complex and is mainly used when stability, robustness, security and complex interactions are required.

PHP integrates access to two protocols, XML-RPC and SOAP, both of which are concentrated in the xmlrpc extension. In addition, in PHP's PEAR, whether it is PHP 4 or PHP 5, the XML-RPC extension has been integrated by default, and this extension has nothing to do with the xmlrpc extension and can independently implement XML-RPC protocol interaction. If there is no xmlrpc extension, it is recommended Use the PEAR::XML-RPC extension.

Here we mainly use XML-RPC to briefly describe the interaction process of Web Service. Some of the content comes from the PHP manual. For more details, it is recommended to refer to the manual.

Install the xmlrpc extension

If the xmlrpc php extension is not installed in your system, please install it correctly.

On the Windows platform, first put the extension php_xmlrpc.dll in the PHP installation directory into the C:Windows or C:Winnt directory. (PHP4 extensions are in the C:phpextensions directory, and PHP5 extensions are in the C:\phpextensions directory. :phpext directory), and remove the semicolon ";" in front of extension=php_xmlrpc.dll in C:Windowsphp.ini or C:Winntphp.ini, then restart the web server and check if there is an XML-RPC project in phpinfo() You can determine whether the xmlrpc extension has been installed correctly.

Under Unix/Linux platform, if the xmlrpc extension is not installed, please recompile PHP, add the --with-xmlrpc option when configure, and then check phpinfo() to see if xmlrpc is installed normally.

(Note: The following operations are based on the normal installation of the xmlrpc expansion, please be sure to install it correctly.)

XML-RPC working principle

XML-RPC roughly means that the entire process uses XML for communication. First, an RPC server is constructed to process XML-encapsulated requests passed from the RPC client, and the processing results are returned to the RPC client in the form of XML. The client then analyzes the XML to obtain the data it needs.

The server side of XML-RPC must have ready-made functions for the client to call, and the functions and methods in the request submitted by the client must be consistent with those on the server side, otherwise the required results will not be obtained.

Below I will use simple code to describe the entire process.

XML-RPC practice

The server uses the xmlrpc_server_create function to generate a server, then registers the RPC calling interface that needs to be exposed, and accepts POST from the RPC client. The XML data is then processed, and the processing results are displayed to the client in the form of XML.

The code is as follows: rpc_server.php


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446650.htmlTechArticleThere are currently two protocol standards for Web Service communication, one is XML-RPC and the other is SOAP. XML-RPC is relatively simple and appeared earlier, while SOAP is more complex, mainly because it requires stability...
source:php.cn
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