PHPRPC for PHP

Jun 23, 2016 pm 02:36 PM

PHPRPC 是一个轻型的、安全的、跨网际的、跨语言的、跨平台的、跨环境的、跨域的、支持复杂对象传输的、支持引用参数传递的、支持内容输出重定向的、支持分级错误处理的、支持会话的、面向服务的高性能远程过程调用协议。
下载地址:http://www.phprpc.org/zh_CN/download/
该版本直接解压后就可以使用,其中
属于公共文件。不论是客户端还是服务器端都需要这些文件。
是客户端文件,如果你只需要使用客户端,那么只要有上面那些公共文件和这个文件就可以使用了,使用时,直接在你的程序中包含 phprpc_client.php 就可以,公共文件不需要单独包含。
这三个文件是服务器端需要的文件。
其中 dhparams 目录中包含的是加密传输时用来生成密钥的参数
dhparams.php 是用来读取 dhparams 目录中文件的类。
phprpc_server.php 是服务器端,如果你要使用 PHP 来发布 PHPRPC 服务,只需要包含这个文件就可以了。公共文件和 dhparams.php 都不需要单独包含。
PHP 4.3+、PHP 5、PHP 6
客户端要求开启 socket 扩展。
服务器端需要有 IIS、Apache、lighttpd 等可以运行 PHP 程序的 Web 服务器。
如果服务器端需要加密传输的能力,必须要保证 session 配置正确。
include('php/phprpc_server.php'); //加载文件
function hello($name) {
return'Hello ' . $name;
}
$server = new PHPRPC_Server(); //创建服务端
$server->add(array('hello', 'md5', 'sha1')); //数组形式一次注册多个函数
$server->add('trim'); //单一注册
$server->start(); //开启服务
?>
include ("php/phprpc_client.php"); //加载文件
$client = new PHPRPC_Client('http://127.0.0.1/server.php'); //创建客户端 并连接服务端文件
echo$client->Hello("word"); //调用方法 返回 hello word
?>
-------------------------------------------------- --------------------------------------------------- ------------------------------
服务端其他说明:
include('php/phprpc_server.php'); //加载文件
function hello($name) {
return'Hello ' . $name;
}
class Example1 {
staticfunction foo() {
return'foo';
}
function bar() {
return'bar';
}
}
$server = new PHPRPC_Server(); //创建服务端
$server->add('foo', 'Example1'); //静态方法直接调用
$server->add('bar', new Example1()); //非静态方法 需要实例化
//注册别名调用
$server->add('hello', NULL, 'hi'); //第三参数是函数的别名 客户端通过别名来调用函数
$server->add('foo', 'Example1', 'ex1_foo');
$server->add('bar', new Example1(), 'ex1_bar');
$server->setCharset('UTF-8'); //设置编码
$server->setDebugMode(true); //打印错误
$server->setEnableGZIP(true); //启动压缩输出虽然可以让传输的数据量减少,但是它会占用更多的内存和 CPU,因此它默认是关闭的。
$server->start(); //开启服务
?>
-------------------------------------------------- --------------------------------------------------- ---------------------------
客户端其他说明:
include ("php/phprpc_client.php");
$client = new PHPRPC_Client();
$client->useService('http://127.0.0.1/server.php'); //远程调用地址
$client->setKeyLength(1000); //密钥长度
$client->setEncryptMode(3); //加密等级0-3
$client->setCharset('UTF-8'); //设置编码
$client->setTimeout(10); //设置超时时间
echo$client->hi('PHPRPC'), "\r\n"; //调用函数
echo$client->getKeyLength(), "\r\n"; //下面是返回值
echo$client->getEncryptMode(), "\r\n";
echo$client->getCharset(), "\r\n";
echo$client->getTimeout(), "\r\n";
?>
-------------------------------------------------- --------------------------------------------------- ----------------------
关于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();
?>
每次刷新都是新建的client 服务端并不能识别.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

See all articles