Reading today, found the Phprpc this good dongdong, so write down here to make notes.
Phprpc is a light, safe, cross-web, Cross-language, Cross-platform, Cross-platform, Cross-domain, complex object-transmitted, support-referenced parameter-passing, support for content-output redirection, support for hierarchical error-handling, session-oriented, serviced, high performance remote procedure call protocol.
Download Address: http://www.phprpc.org/zh_CN/download/This version can be used directly after decompression, including bigint.php, compat.php, phprpc_date.php, xxtea.php belong to public files. These files are required on both the client and server side.
Phprpc_client.php is the client file, if you only need to use the client, then as long as the above public files and this file can be used, when used, directly in your program contains phprpc_client.php can be, public files do not need to be included separately.
Dhparams, dhparams.php phprpc_server.php These three files are server-side required files. The Dhparams directory contains the parameters that are used to generate the key when the transmission is encrypted. Dhparams.php is a class used to read files in the Dhparams directory. Phprpc_server.php is the server side, if you want to use PHP to publish the PHPRPC service, only need to include this file. Public files and dhparams.php are not required to be included separately.
PHP 4.3+, PHP 5, PHP 6
The client requires the socket extension to open.
The server side needs to have IIS, Apache, LIGHTTPD, and other WEB servers that can run PHP programs.
If the server side requires the ability to encrypt the transmission, you must ensure that the session is configured correctly.
Example:
Server side:
<?php
Include ("phprpc/phprpc_server.php");
Class Hello {
static function HelloWorld ()
{
Return ' Hello world! ';
}
}
$server = new Phprpc_server ();
$server->add (' HelloWorld ', ' hello ');
$server->start ();
?>
Client:
<?php
Include ("phprpc/phprpc_client.php");
The URL here is the server-side address
$client = new Phprpc_client ("http://127.0.0.1/immoc/phprpc_server.php");
echo $client->helloworld ();
?>
After running, a fatal error:cannot redeclare gzdecode () in D:\wamp\www\immoc\phprpc\compat.php to line 182 appears
Error.
The reason for this problem is that PHP has included the Gzdecode () function since version 5.4, and the Gzdecode () function defined by the developer will conflict with it.
Knowing the cause of the mistake, it is very convenient to solve it. In the 72nd line of the ... \phprpc\compat.php file (here, may be different), find the function Gzdecode ($data, & $filename = ', & $error = ', $maxlength = null), include this function in the following code:
if (! function_exists (' Gzdecode ')) {
Include the Gzdecode function in
}
。 After doing this, run the program again and get the results we want: