- 浏览: 590781 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
kangh:
转载的也拿出来 都不试一下 完全错误
Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解 -
wangtxlz:
#cd builders/cmake#cmake .系统提示命 ...
crtmpserver流媒体服务器的介绍与搭建 -
hnraysir:
支持支持支持
手机Android音视频采集与直播推送,实现单兵、移动监控类应用 -
wuent:
把web服务器和php框架绑定到一起?真不建议这样。。。
Swoole(PHP高级Web开发框架) -
wuent:
有更详细的性能比较吗?php,python,java
PHP中的(伪)多线程与多进程
一.XML-RPC是什么?
XML-RPC是Userland Software公司设计的一种格式:是一种使用HTTP协议传输XML格式文件来获取远程程序调用(Remote Procedure Call)的传输方式。官方网站是www.xmlrpc.com。
在http://phpxmlrpc.sourceforge.net/上面有个PHP XML-RPC的框架(类集合)用于使用PHP语言来写XML-RPC客户端和服务端。现在的稳定发行版本是2.2,下载地址是http://sourceforge.net/projects/phpxmlrpc/files/phpxmlrpc/2.2.2/xmlrpc-2.2.2.tar.gz/download。
另外你在www.xmlrpc.com上面也可以找到其他s语言的XML-RPC列表,例如Perl、Python。
这篇文章将介绍XML-RPC for PHP的类库使用。
二.系统运行要求
该类库的设计目标是可扩展性和向后兼容性。因此,它支持大部分的现有PHP版本。最低需要的PHP版本是4.2。该类库提供一个兼容层来支持PHP 4.0.5和4.1。当然官方建议是使用PHP 5.0或者更高版本。
注意,如果你要用SSL或者HTTP 1.1跟远程服务器通信,必须把“CURL”扩展编译进PHP中。
另外,PHP自带的原生“xmlrpc”扩展跟这里介绍的XML-RPC类库不是同一个东西,所以并不需要将其编译进PHP中。
三.相关类介绍
1.xmlrpcval
在XML-RPC中有六种基本类型和两种复合类型,基本类型是:int、boolean、string、double、dateTime.iso8601、base6,复合类型是:array、struct。Xmlrpcval的作用就是把PHP中类型转换成这几种类型放入XML-RPC中,以便传输。
new xmlrpcval(123,"int"); //将123作为XML-RPC int类型
new xmlrpcval(123,"string"); //将123作为XML-RPC string类型
new xmlrpcval(123);//如果没有第二个参数,系统默认将其作为string类型
new xmlrpcval( //XML-RPC array类型
array(
new xmlrpcval("string1"),
new xmlrpcval("string2"),
new xmlrpcval("string3"),),"array");
new xmlrpcval( //XML-RPC struct类型
array( "name"=>new xmlrpcval("codebean","string"),
"age"=>new xmlrpcval(34,"int"),
"address"=>new xmlrpcval(
array( "street"=>new xmlrpcva("xiaoyinxilu","string"), "city"=>new xmlrpcval("beijing","string") ),
"struct")),
"struct");
相关方法:
kindOf():返回该对象的基本类型:"struct","array","scalar"。
scalarVal():如果$val->kindOf()=="scalar",则直接返回改对象的PHP对应的值。
arrayMen(int $n):如果$val->kindOf()=="array",返回$val中第n个的值。
arraySize():如果$val->kindOf()=="array",返回$val的元素个数。
2.xmlrpcmsg
这个类提供一个向XML-RPC服务器发送请求的对象,客户端发送xmlrpcmsg到服务器,服务器返回一个xmlrpcresp。
//请求服务器的examples.getStateName方法,参数是123
$message = new xmlrpcmsg("examples.getStateName",array(new xmlrpcval(123,"int")));
相关函数:
getNumParams():获取xmlrpcmsg对象的参数的总数。
getParam(int $n):获取xmlrpcmsg对象的第n个数的值。
3.xmlrpc_client
客户端的基本类。
//在服务端www.test.com上面的interface.php路径建立相关链接。
$client = nw xmlrpc_client("/interface.php","ww.test.com",80);
相关方法:
send($message,30):向服务端发送$message,超时时间是30秒。
setDebug(int $level):设置是否输出调试信息,默认是0即不输出调试信息。$level是1,打印服务端的HTTP头信息及XML信息。$level是2,同时打印服务端和客户端的HTTP头信息及XML信息。
4.xmlrpcresp
该类主要包含XML-RPC请求返回的结果。Xmlrpc_client的send方法返回该类型。
new xmlrpcresp(xmlrpcval $val);//在服务端生成一个xmlrpcresp对象
new xmlrpcresp(0,int $errcode,string $err_string);//服务端出错时,可以返回该类型。
相关方法:
faultCode():客户端获取服务端返回的出错代码。
faultString():客户端获取服务端返回的出错信息。
Value():客户端获取服务端返回的值。
5.xmlrpc_server
服务端的基本类。
function test($xmlrpcval){
return new xmlrpcresp($val);
}
//客户端可以访问examples.myTest来实际访问test()函数
new xmlrpc_server(
array(
"examples.myTest"=>array("function"=>"test")
));
四,一个实际例子
假设服务度是my.rpcserver.com,提供服务的路径是interface.php,客户端是my.test.com.
在服务度的interface.php中:
<?php
include './lib/xmlrpc.inc';
include './lib/xmlrpcs.inc';
function foo($xmlrpcmsg){
$par1 = $xmlrpcmsg->getParam(0); //获取第一个参数
$val1 = $par1->scalarval(); //转换成PHP对应的值
$par2 = $xmlrpcmsg->getParam(1); //获取第二个参数
$val2 = $par2->scalarval(); //转换成PHP对应的值
$par3 = $xmlrpcmsg->getParam(2); //获取第二个参数
//转换成PHP对应的值
for($i=0; $i<$par3->arraySize(); $i++){
$v = $par3->arrayMem($i);
$val[] = $v->scalarVal()."<br>";
}
$msg1 = new xmlrpcval(strrev($val1),"string");
$msg2 = new xmlrpcval(strrev($val2),"int");
$msg = new xmlrpcval(array($msg1,$msg2),"array"); //返回一个array
return new xmlrpcresp($msg);
}
new xmlrpc_server(
array(
"example.test"=>array("function"=>"foo"),
)
);
?>
在客户端的client.php中:
<?php
include './lib/xmlrpc.inc';
$params = array(
new xmlrpcval("hello rpc","string"),
new xmlrpcval(123,"int"),
new xmlrpcval(
array(
new xmlrpcval("test","string"),
new xmlrpcval(456,"int")
),
"array"),
);
$message = new xmlrpcmsg("example.test",$params);
$client = new xmlrpc_client("/interface.php", "my.rpcserver.com" ,'80');
//$client->setDebug(2);
$res = $client->send($message,30);
if(!$res->faultCode()){
$v= $res->value();
for($i=0; $i<$v->arraySize(); $i++){
$vv = $v->arrayMem($i);
echo $vv->scalarVal()."<br>";
}
}else{
echo $res->faultcode().":".$res->faultString()."<br>";
}
?>
发表评论
-
nginx、php-fpm默认配置与性能–TCP socket还是unix domain socket
2015-04-02 11:14 1414前几天看到一篇博客,提到php所在服务器在大并发情况下,频 ... -
使用socket方式连接Nginx优化php-fpm性能
2015-04-01 13:49 0Nginx连接fastcgi的方式有 ... -
PHP中include和require的区别详解
2015-04-01 08:32 01、概要 require()语句的性能与includ ... -
PHP 中cookie 和 session 的分析
2015-03-31 12:33 0HP 中cookie 和session 的分析 ... -
php 经典的算法题你懂的
2015-03-31 12:31 0有5个人偷了一堆苹果,准备在第二天分赃。晚上,有一人遛出来, ... -
PHP最常用的2种设计模式工厂模式和单例模式介绍
2015-03-31 12:26 0简单来说,PHP单例模式就是一个功能用一个类来实现,并且在整 ... -
PHP 数据类型
2015-03-31 12:23 0PHP 数据类型 PHP 支持八种原始类型(type)。 ... -
PHP mcrypt启用、加密以及解密过程详解
2015-03-30 11:32 1416Mcrypt扩展库可以实现加密解密功能,就是既能将明文加密, ... -
PHP扩展实现类扩展
2015-03-27 14:08 527在第一篇文章中,我们所开发的扩展是单个函数,本篇文章看一下 ... -
PHP高级工程师的面试题
2015-03-06 10:35 01. 基本知识点 HTTP协议中几个状态码的含义:1x ... -
PHP面试中常见的面试试题与算法例子
2015-03-05 14:14 0下面是四道比较常见的题目,主要考察的是对字符串函数以及文件操 ... -
PHP实现四种常用的排序算法
2015-03-05 14:09 0插入排序(Insertion Sort),选择排序(Sele ... -
用swagger-php/ui做API测试
2015-02-13 09:46 3600功能: 1 swagger-php根据自定义的规则生成API ... -
app后端设计(0)--总目录
2015-01-23 18:03 0做了3年app相关的系统架构,api设计,先后在3个创业公司中 ... -
PHP中eAccelerator、memcached、xcache、APC 4个加速、缓存扩展的区别
2015-01-23 10:26 874这篇文章主要介绍了PHP ... -
PHP内核探索:zend_parse_parameters函数
2015-01-16 14:14 907最简单的获取函数调用者传递过来的参数便是使用zend_pars ... -
实战:用C写php扩展(二)
2015-01-16 11:05 942一、前言 在我的上一篇文章“实战:用C写php扩展(一)”里介 ... -
实战:用C写php扩展(一)
2015-01-16 11:04 9751、 前言 首先,确保你的机器安装了apache和php。假 ... -
JavaScript or PHP 来检测移动设备
2014-09-22 10:04 591iPhone & iPod Detection T ... -
YII Framework学习教程-YII的Modules(模块化)
2014-08-27 11:04 711一个相对来说大的项目。如果按照yii生成的 ...
相关推荐
The automatic base64 encoding can be turned on via the new XML_RPC_Client::setAutoBase64() method. The auto-encoding is a workaround for systems that don't have PHP's mbstring extension ...
XML-RPC Web RPC协议PHP实现。 额外的模块提供对JSON和JSONRPC协议的支持。 该库的javascript版本也可用。
Learn how to use SAX, XSLT, and XPath to manipulate XML documents, as well as use of XML-RPC protocol for accessing procedures on a remote computer, and much more
It is a library implementing the XML-RPC protocol, written in PHP. It is also known as PHPXMLRPC. It is designed for ease of use, flexibility and completeness. High speed and reduced memory footprint ...
we create an extensible object-oriented parser for XML. The mashup covered in this chapter integrates information taken from Amazon's E-commerce Service (ECS) with the Internet UPC database. In ...
YACS 是一个强大的 PHP 脚本,可以让你维护一个动态的 Web 服务器。... RSS syndication- Easy installation- XML-RPC interface (implementing the Blogger API and metaWeblog API) 标签:YACS
the way, I address some of the important protocols, such as SOAP and XML-RPC, that make seamless data transfer possible. Throughout this book you’ll find sample scripts. You can download the complete...
XML-RPC 函数 CLVIII. XMLReader functions CLIX. XSL functions CLX. XSLT Functions CLXI. YAZ Functions CLXII. YP/NIS Functions CLXIII. Zip File Functions (Read Only Access) CLXIV. Zlib Compression ...
XML-RPC 函数 CLXIV. XMLReader functions CLXV. XSL functions CLXVI. XSLT Functions CLXVII. YAZ Functions CLXVIII. YP/NIS Functions CLXIX. Zip File Functions (Read Only Access) CLXX. Zlib Compression ...
XML-RPC — XML-RPC 函数 XMLReader — XMLReader functions XMLWriter — XMLWriter Functions XSL — XSL functions XSLT — XSLT Functions YAZ — YAZ Functions YP/NIS — YP/NIS Functions Zip — Zip File ...
should be disabled, as enabling it may result in issues when generating XML ; documents, however this remains supported for backward compatibility reasons. ; Note that this directive does not control...
this practical book provides everything you need to build web service APIs with PHP. Author Lorna Jane Mitchell uses code samples, real-world examples, and advice based on her extensive experience to...
XML-RPC — XML-RPC 函数 XMLReader — XMLReader functions XMLWriter — XMLWriter Functions XSL — XSL functions XSLT — XSLT Functions YAZ — YAZ Functions YP/NIS — YP/NIS Functions Zip — Zip File ...
XML-RPC 函数 CLVIII. XMLReader functions CLIX. XSL functions CLX. XSLT Functions CLXI. YAZ Functions CLXII. YP/NIS Functions CLXIII. Zip File Functions (Read Only Access) CLXIV. Zlib Compression ...
XML-RPC 函数库 CXVIII. xdiff Functions CXIX. XSLT Functions CXX. YAZ Functions CXXI. YP/NIS Functions CXXII. Zip File Functions (Read Only Access) CXXIII. Zlib Compression Functions VI. Zend API 24. ...
XML-RPC 函数 CLVIII. XMLReader functions CLIX. XSL functions CLX. XSLT Functions CLXI. YAZ Functions CLXII. YP/NIS Functions CLXIII. Zip File Functions (Read Only Access) CLXIV. Zlib Compression ...
XML-RPC 函数 CLVIII. XMLReader functions CLIX. XSL functions CLX. XSLT Functions CLXI. YAZ Functions CLXII. YP/NIS Functions CLXIII. Zip File Functions (Read Only Access) CLXIV. Zlib Compression ...
XML-RPC 函数 CLVIII. XMLReader functions CLIX. XSL functions CLX. XSLT Functions CLXI. YAZ Functions CLXII. YP/NIS Functions CLXIII. Zip File Functions (Read Only Access) CLXIV. Zlib Compression ...
XML-RPC 函数 CLVIII. XMLReader functions CLIX. XSL functions CLX. XSLT Functions CLXI. YAZ Functions CLXII. YP/NIS Functions CLXIII. Zip File Functions (Read Only Access) CLXIV. Zlib ...
XML-RPC 函数 CLXXXII. XMLReader functions CLXXXIII. XMLWriter Functions CLXXXIV. XSL functions CLXXXV. XSLT Functions CLXXXVI. YAZ Functions CLXXXVII. YP/NIS Functions CLXXXVIII. Zip File Functions ...