Phprpc for PHP

Source: Internet
Author: User
PHPRPC is a lightweight, secure, cross-network, cross-lingual, cross-platform, cross-domain, cross-field, multi-tiered, support-enabled, service-oriented, high-performance remote procedure call protocol that supports the transfer of reference parameters, supports content output redirection, supports hierarchical error handling, and supports session.
Download Address: http://www.phprpc.org/zh_CN/download/
This version can be used directly after decompression, where
belongs to the public file. These files are required both on the client and on the server side.
Is the client file, if you only need to use the client, then as long as there are those public files and this file can be used, when used, directly in your program contains phprpc_client.php, public files do not need to be included separately.
These three files are required on the server side.
Where the Dhparams directory contains the parameters used to generate the key when the encryption is transmitted
Dhparams.php is the 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. Both public files and dhparams.php do not need to be included separately.
PHP 4.3+, PHP 5, PHP 6
The client requires the socket extension to be turned on.
The server side needs to have IIS, Apache, lighttpd and so on Can run PHP program Web server.
If the server side requires the ability to encrypt the transfer, it must ensure that the session is configured correctly.
Include (' php/phprpc_server.php '); Loading files
function Hello ($name) {
Return ' Hello '. $name;
}
$server = new Phprpc_server (); Create a service-side
$server->add (Array (' Hello ', ' md5 ', ' SHA1 ')); Array form to register multiple functions at once
$server->add (' trim '); Single Sign-on
$server->start (); Open service
?>
Include ("php/phprpc_client.php"); Loading files
$client = new Phprpc_client (' http://127.0.0.1/server.php '); Create a client and connect to a server file
Echo$client->hello ("word"); Call method returns Hello Word
?>
-------------------------------------------------- --------------------------------------------------- ---------- --------------------
Other instructions on the service side:
Include (' php/phprpc_server.php '); Loading files
function Hello ($name) {
Return ' Hello '. $name;
}
Class Example1 {
Staticfunction foo () {
Return ' foo ';
}
function Bar () {
return ' bar ';
}
}
$server = new Phprpc_server (); Create a service-side
$server->add (' foo ', ' Example1 '); static method calls directly
$server->add (' Bar ', New Example1 ()); Non-static methods need to be instantiated
Registering alias Calls
$server->add (' Hello ', NULL, ' Hi '); The third parameter is the alias of the function the client calls the function through an alias
$server->add (' foo ', ' Example1 ', ' Ex1_foo ');
$server->add (' Bar ', New Example1 (), ' Ex1_bar ');
$server->setcharset (' UTF-8 '); Set encoding
$server->setdebugmode (TRUE); Print error
$server->setenablegzip (TRUE); Starting a compressed output can reduce the amount of data transferred, but it consumes more memory and CPU, so it is turned off by default.
$server->start (); Open service
?>
-------------------------------------------------- --------------------------------------------------- ---------- -----------------
Additional instructions for the client:
Include ("php/phprpc_client.php");
$client = new Phprpc_client ();
$client->useservice (' http://127.0.0.1/server.php '); Remote Call Address
$client->setkeylength (1000); Key length
$client->setencryptmode (3); Encryption Level 0-3
$client->setcharset (' UTF-8 '); Set encoding
$client->settimeout (10); Setting the time-out period
Echo$client->hi (' Phprpc '), "\ r \ n"; Calling functions
Echo$client->getkeylength (), "\ r \ n"; The following is the return value
Echo$client->getencryptmode (), "\ r \ n";
Echo$client->getcharset (), "\ r \ n";
Echo$client->gettimeout (), "\ r \ n";
?>
-------------------------------------------------- --------------------------------------------------- ---------- ------------
About session
Include (' php/phprpc_server.php ');
Class Examplecounter {
function Examplecounter () {
if (!isset ($_session[' count ')) {
$_session[' count '] = 0;
}
}
Function Inc () {
$_session[' count '] + = 1;
}
Functioncount () {
return$_session[' count '];
}
}
$server = new Phprpc_server ();
$server->add (Array (' Inc ', ' Count '), new Examplecounter ());
$server->start ();
?>
Include ("php/phprpc_client.php");
$client = Newphprpc_client ();
$client->useservice (' http://127.0.0.1/1.php ');
$client->settimeout (10);
echo $client->inc ();
echo $client->count ();
echo $client->inc ();
echo $client->count ();
?>
Each refresh is new to the client server and is not recognized.
  • 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.