Home > Article > Backend Development > Simple use of PHPRPC
PHPRPC is a lightweight, secure, cross-internet, cross-language, cross-platform, cross-environment, cross-domain, supports complex object transmission, supports reference parameter passing, supports content output redirection, and supports A hierarchical error-handling, session-enabled, service-oriented, high-performance remote procedure call protocol. To learn more please visit http://www.phprpc.com.
Click the link above to download the php version from the official website, and unzip the compressed package to the root directory of the website (mine is phprpc). Create two test files server.php and client.php in the root directory.
server.php code:
<?php include ("php/phprpc_server.php"); $server = new PHPRPC_Server(); $server->add('HelloWorld'); $server->start(); <pre name="code" class="php"> function HelloWorld() { return 'Hello World!'; }?>
client.php code:
<?php include ("php/phprpc_client.php"); $client = new PHPRPC_Client('http://localhost/server.php'); echo $client->HelloWorld(); ?>uses a browser to access http://127.0.0.1/client.php, and "Hello World!" is output normally. If there is an error like the one below, the reason is that when PHPRPC mode is enabled after version 5.4, PHP already contains the gzdecode() function, and the gzdecode() function defined by the developer will conflict with it. Solution: Open phprpccompat.php, find function gzdecode($data, &$filename = '', &$error = '', $maxlength = null) on line 72 (there may be differences), use this function as follows Just include the code.
if (! function_exists('gzdecode')) { //将gzdecode函数包括进来 }