怎样看redis的redis 历史记录操作记录

XML-RPC 函数-PHP手册
keithNO dot SPAMthornhill at gmail dot com
for others attempting the same thing, here is what a function would look like if you wanted to send a base64 encoded file from a client and then save it onto the server. the other code necessary to call this function via an RPC is available in other comments so i won't repeat it.
parameters:
1 - name of file
2 - base64 encoded data of file
note the use of $file_data-&scalar
function sendFile($method_name, $params, $user_data) {
$file = "/somedir/" . $params[0];
$file_data = $params[1];
$fh = @fopen($file, "wb");
if ($fh) {
&& & & & &
if (@fwrite($fh, $file_data-&scalar)) {
&& & & & & & &
$msg = "success msg";
&& & & & &
&& & & & & & &
$msg = "couldn't write to file";
&& & & & &
&& & & & &
fclose($fh);
&& & & & &
return $msg;
&& & & & &
return "couldn't open file";
This XML-RPC Service makes the use XML-RPC very esay.
* function myfun() returns&
*@return array
function myfunc(){
return $some_array;
$ws = new XML_RPC_Server();
$ws-&registerFunction('myfunc');
$ws-&run();
It creates also a simple docu.
john # curioussymbols com
I couldn't make the 'xmlrpc_errors' php.ini setting do anything
noticeable (PHP 4.3.11), so I used the following code to report errors
from my XMLRPC server. Hope it's helpful for someone.
function return_xmlrpc_error($errno,$errstr,$errfile=NULL,$errline=NULL
&& & & ,$errcontext=NULL){
global $xmlrpc_server;
if(!$xmlrpc_server)die("Error: $errstr in '$errfile', line '$errline'");
header("Content-type: text/ charset=UTF-8");
print(xmlrpc_encode(array(
'faultCode'=&$errno
,'faultString'=&"Remote XMLRPC Error from
".$_SERVER['HTTP_HOST'].": $errstr in at $errfile:$errline"
set_error_handler('return_xmlrpc_error');
In my server function, I just trigger_error("message",E_USER_ERROR)]
&if something can't be completed.
Then on the client side,
$data =& xmlrpc_decode($response['body']);
if(xmlrpc_is_fault($data)){
&& & & & &
trigger_error($data['faultString'],E_USER_ERROR);
martin dot rode at programmfabrik dot de
To connect to a python xmlrpc server I use:
function do_call($host, $port, $request) {
$url = "";
$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($request);
$ch = curl_init();&
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
$data = curl_exec($ch);& & &
if (curl_errno($ch)) {
print curl_error($ch);
curl_close($ch);
$request = xmlrpc_encode_request('add', array(3, 4));
$response = do_call($host, $port, $request);
astrolox at lawyersonline dot co dot uk
The PHP XML-RPC project at SourceForge makes life a hell of a lot easier. However, the project uses some function names which are identical to thoses provided by the XML-RPC extention.
If you are on a server with XML-RPC extension compiled in but wish to use the PHP based version then you will have to rename some of the functions.
I notice that sourceforce says there is activity on the project in 2005 but the last release was January 12, 2003.
I recommend that you use this not so friendly PHP extention if available. However this sourceforce project is still a good idea if you don't control which extenions are be available on the server.
rdude at fuzzelfish dot com
An easier alternative to the built-in XML-RPC function is available at:
PHP XML-RPC is written purely in PHP, so there is no need to recompile to use the experiment XML-RPC extension. PHP XML-RPC is also definitely easier to use, especially if you are creating a server. Documentation is available at the above link.
Jerome Delamarche
The documentation lacks an example that shows how to send a fault in a response. Here is how to do it:
$args = array("faultCode" =& $errcode, "faultString" =& $errmsg);
$resp = xmlrpc_encode_request(NULL,$args);
php at hendrik-krauss dot de
On "datetime" values:
If you implement an XML-RPC server with these functions and a client calls a method on your server, sending a datetime as parameter (in ISO 8601 format, as specified at ), the PHP XML-RPC will pass your registered server method an object as parameter. That object, for example, looks like:
obj-&type="datetime"
obj-&scalar=":32:40"
obj-&timestamp=
If you do xmlrpc_get_type(obj), it will return "datetime", so presumably that function just returns the value of 'type'. 'scalar' seems to be the on-the-wire representation of the datetime (ISO 8601, exactly as received). 'timestamp' appears to be the ISO value in 'scalar' converted into a normal PHP timestamp (i.e. Unix time_t).
Note on 'scalar': Using a MySQL DB, we did something like& "select blah where start_time &= $obj-&". That actually worked and returned expected results, so MySQL appears to handle that ISO 8601 format correctly.
swunderlin at REMOVE-telemedia dot ch
pear hs an XML_RPC package, if you can't recompile your php:
steph at zend dot com
It took me a while to get a client together without external libraries.& This very basic client/server pair works on my home set-up - hopefully it will save the next xml-rpc virgin some grief.
/* clienttest.php */
function do_call($host, $port, $request) {
$fp = fsockopen($host, $port, $errno, $errstr);
$query = "POST /home/servertest.php HTTP/1.0\nUser_Agent: My Egg Client\nHost: ".$host."\nContent-Type: text/xml\nContent-Length: ".strlen($request)."\n\n".$request."\n";
if (!fputs($fp, $query, strlen($query))) {
$errstr = "Write error";
$contents = '';
while (!feof($fp)) {
$contents .= fgets($fp);
fclose($fp);
return $contents;
$host = 'localhost';
$port = 80;
$request = xmlrpc_encode_request('cycle', 'egg');
$response = do_call($host, $port, $request);
/* do something with $response, e.g. print it */
/* servertest.php */
function lifecycle($method, $params) {
/* $method = 'cycle', $params = (array of) request parameter(s); $data is also passed from xmlrpc_server_call_method, if we had any data to pass */
switch($params[0]) {
case 'egg':
&& & & & &
$reply = 'All eggs will be birds one day.';
&& & & & &
$reply = 'That must have been an otheregg';
return $reply;
$server = xmlrpc_server_create();
/* register the 'external' name and then the 'internal' name */
xmlrpc_server_register_method($server, "cycle", "lifecycle");
$request = $HTTP_RAW_POST_DATA; // no you don't need 'always on', and no $_POST doesn't work.
/* the parameters here are 'server, xml-string and user data'.& There's supposed to be an optional 'output options' array too, but I can't get it working :( hence header() call */
$response = xmlrpc_server_call_method($server, $request, null);
header('Content-Type: text/xml');
print $response;
xmlrpc_server_destroy($server);
devshed article is at
mboeren at php dot net
Just a quick addition to my previous xmlrpc_client class: since you cannot use remote methods containing capital letters or methods from subhandlers (like 'system.listMethods()'), I added a 'call(...)' method to the class.
// this method should be copy/pasted in the
// xmlrpc_client class
function call($function)
$return = NULL;
$argv = func_get_args();
array_shift($argv); // remove function argument
$this-&__call($function, $argv, &$return);
return $return;
// now, you can also do
$result = $client-&call('system.listMethods');
$sum = client-&call('add', '1', '2');
mboeren at php dot net
I use the following code (requires the overload extension) to make developing clients easier:
include("utils/utils.php"); // from xmlrpc-epi utils
$client = new xmlrpc_client("");
print $client-&echo('x')."\n";
print $client-&add(1, 3)."\n";
class xmlrpc_client
var $urlparts;
function xmlrpc_client($url)
$this-&url = $url;
$this-&urlparts = parse_url($this-&url);
foreach(array('scheme', 'host', 'user', 'pass', 'path',
&& & & & & & & & & &
'query', 'fragment')
&& & & & & & &
as $part) {
&& & & & &
if (!isset($this-&urlparts[$part])) {
&& & & & & & &
$this-&urlparts[$part] = NULL;
&& & & & & & &
&& & & & &
function __call($function, $arguments, &$return)
$requestprms['host'] = $this-&urlparts['host'];
$requestprms['port'] = $this-&urlparts['port'];
$requestprms['uri'] = $this-&urlparts['path'];
$requestprms['method'] = $function;
$requestprms['args'] = $arguments;
$requestprms['debug'] = 0;
$requestprms['timeout'] = 0;
$requestprms['user'] = NULL;
$requestprms['pass'] = NULL;
$requestprms['secure'] = 0;
$result = xu_rpc_http_concise($requestprms);
if (is_array($result) && isset($result['faultCode'])) {
&& & & & &
print('Error in xmlrpc call \''.$function.'\''."\n");
&& & & & &
print('& code&
: '.$result['faultCode']."\n");
&& & & & &
print('& message: '.$result['faultString']."\n");
&& & & & &
return false;
&& & & & &
$return = $result;
return true;
overload('xmlrpc_client');
here's how to install it on windows (so it actually works):
- php.ini & enable "php_xmlrpc.dll" in extensions.
- php.ini & make sure "extension_dir" is set correctly to find the dll in your php installation dir /extensions.
- copy iconv.dll from your php install dir /dlls to a directory in your path (ex: c:/windows).
if you got some errors while launching apache prior to trying this I suggest you reboot your machine first... sounds weird I know, but remember... you're running Windowz.
sjtirtha at gmx dot de
To install xml-rpc feature on Windows, you need to have "php_xmlrpc.dll" on your "/extensions" Folder.
And you need to enable it on "php.ini".
You need also library from
to make your code simply.
Look the examples at
mistcat attyatatat phreaker dootttt net
Hope this saves somone some frustration:
As of php 4.3.1 and xmlrpc-epi-php-0.51 php would return a content type text/html instead of text/xml in its responses.& this is a bad thing.& Perl's XMLRPC::Lite for instance will not like you if you do this.& Happily the solution is simple:
header("Content-Type: text/xml");
Happy Hunting.
daniel(at)lorch.cc
If you need a tutorial on the XML-RPC-Extension go to devshed:
bmichael at goldparrot dot com
If anyone is interested in making XMLRPC requests directly from the client, I have been able to get xmlrpc to
work with vcXMLRPC javascript backend.
After about 1 week of scanning the market, I found this solution to be the best on Javascript back end.& It uses the Microsoft.HTTP activeX control for IE, or HTTPRequest Object for Mozilla.
You include vc(Virtual Cowboys) vcXMLRPC.js file into your pages and make the rpc calls from with javascript to create the requests.
It works both ways.
Two Notes:
I have tested it on IE 6.02 and you need to change lines in ProcessRequest :
function to read:
& dom = this.getObject("XMLDOM",http.responseText);
and change the getObject function to use the latest ActiveX Control:
&MSXML2.XMLHTTP.3.0& (or 4.0)
&MSXML2.DOMDocument.3.0& (or 4.0)
The controls are found on MSDN in the Web Services -& XML area.
As another note, you DO NOT NEED the rpcproxy.cgi script to use this.& That is a proxy script to get around JS Security.& You can use PHP to build the proxy.& But, I was able to get the CGI working with GCC compiler on Solaris (change the -KPCI, depend and -x03 optimizer settings in the Makefile )
roland at php dot net
You can find a good howto about the xml-rpc extension at
It's an easy client / server example - works quite good :-)
nospam at phppatterns dot com
Note that you do need the iconv module installed to use the XML-RPC extension (see: )
hfuecks at pinkgoblin dot com
You can pass PHP errors with the XML-RPC extension as described here:
steve at orangeNOSPAMimagineering dot com
There's a handy library by Keith Devens (version 2.2.1) at
Here is a sample client. It remotely calls sample.sumAndDifference
with two parameters (3 and 5).
It returns:
difference =& -2
include ("kd_xmlrpc.php");
// define("XMLRPC_DEBUG", 0);& & // Set to 1 for handy debugging
$method = "sample.sumAndDifference";
$params = XMLRPC_prepare(array(3,5));
$site = "xmlrpc-c.sourceforge.net";
$location = "/api/sample.php";
list($success, $result) = XMLRPC_request( $site, $location, $method, $params );
// XMLRPC_debug_print();& & // uncomment for debugging
foreach ( $result as $key =& $value ) {
echo(" $key =& $value \n");
hfuecks at pinkgoblin dot com
This extension does not handle the process of making making XML-RPC client requests via HTTP; it only prepares the XML-RPC request payload.
This differs from many other XML-RPC implementations but offers greater flexibility, allowing SSL connections, authentication headers and XML-RPC via other transports like SMTP.
hfuecks at pinkgoblin dot com
Anyone interested in PHP-GTK talking to an XML-RPC server:
webkreator dot com
For a really easy way to use this XML-RPC extension take a look at
XML-RPC Class Server ()
It automatically creates servers out of PHP classes. Creating clients is almost as easy, especially with the recent addition of the overload extension to PHP (see ).
nic at uklinux dot NOSPAM dot net
An alternative XML-RPC implementation is available at
- it's written in PHP so you can use it on servers for which you don't have the luxury of rebuilding PHP on.
cmv at php dot net
"Latest releases" is a bit redundant, since this extension is bundled into PHP (as of 4.1.0).& You don't need to download anything from sourceforge to make this work.& Just compile PHP with the --with-xmlrpc flag.
is useful, however, for documentation.
ravan_n at hotmail dot com
Refer to the below link for documentation / latest releases of the package.Linux下PHP安全设置
&PHP安全性设置提示:
DocumentRoot: /var/www/
Default Web server: Apache
Default PHP configuration file: /etc/php.ini
Default PHP extensions config directory: /etc/php.d/
Our sample php security config file: /etc/php.d/security.ini (you need to create this file using a text editor)
Operating systems: Ubuntu (the instructions should work with any other Linux distributions such as RHEL / CentOS / Fedora or other Unix like operating systems such as OpenBSD/FreeBSD/HP-UX).&
1. 减少PHP内置模块
为了增强性能和安全性,强烈建议,减少PHP中的模块。来看看下面这个被执行命令安装的模块。
你将会得到类似的结果:
[PHP Modules]
pdo_sqlite
Reflection
[Zend Modules]
删除一个模块,并执行此命令。例如:删除模块sqlite3
# rm /etc/php.d/sqlite3.ini &&
# mv /etc/php.d/sqlite3.ini /etc/php.d/sqlite3.disableRestrict&
2. 使PHP信息泄露最小化
在默认PHP时在HTTP抬头处会生成一条线介于每个响应中,(比如X-Powered-By: PHP/5.2.10)。而这个在系统信息中为攻击者创建了一个非常有价值的信息。
HTTP示例:
HTTP/1.1 200 OK &
X-Powered-By: PHP/5.2.10 &
Content-type: text/ charset=UTF-8 &
Vary: Accept-Encoding, Cookie &
X-Vary-Options: Accept-Elist-contains=gzip,Cstring-contains=wikiT &
string-contains=wikiLoggedOstring-contains=wiki_session&
Last-Modified: Thu, 03 Nov :55 GMT &
因此,我们强烈建议,禁止PHP信息泄露,想要要禁止它,我们要编辑/etc/php.d/secutity.ini,并设置以下指令:
expose_php=Off&
3. 使PHP加载模块最小化
在默认情况下,RHEL加载的所有模块可以在/etc/php.d/目录中找到。要禁用或启用一个特定的模块,只需要在配置文件/etc/php.d/目录中中注释下模块名称。而为了优化PHP性能和安全性,当你的应用程序需要时,我们强烈建议建议启用扩展功能。举个例子:当禁用GD扩展时,键入以下命令:
# cd /etc/php.d/ &
&# mv gd.{ini,disable} &
&# /etc/init.d/apache2 restart&
为了扩展PGP GD模块,然后键入以下命令:
# mv gd.{disable,ini} &
&# /sbin/service httpd restart&
4. 记录PHP错误信息
为了提高系统和Web应用程序的安全,PHP错误信息不能被暴露出。要做到这一点,需要编辑/etc/php.d/security.ini 文件,并设置以下指令:
display_errors=Off&
为了便于开发者Bug修复,所有PHP的错误信息都应该记录在日志中。[1]&&&
【声明】:黑吧安全网()登载此文出于传递更多信息之目的,并不代表本站赞同其观点和对其真实性负责,仅适于网络安全技术爱好者学习研究使用,学习中请遵循国家相关法律法规。如有问题请联系我们,联系邮箱,我们会在最短的时间内进行处理。
上一篇:【】【】PHP采用XML-RPC构造Web Service实例教程
投稿:shichen2014
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了PHP采用XML-RPC构造Web Service,需要的朋友可以参考下
一、概述:
目前进行Web Service通信有两种协议标准,一种是XML-RPC,另外一种是SOAP。XML-RPC比较简单,出现时间比较早,SOAP比较复杂,主要是一些需要稳定、健壮、安全并且复杂交互的时候使用。
PHP自身就集成了XML-RPC和SOAP两种协议的访问,都是集中在xmlrpc扩展当中。另外,在PHP的PEAR中,不管是PHP 4还是PHP 5,都已经默认集成了XML-RPC扩展,而且该扩展跟xmlrpc扩展无关,能够独立实现XML-RPC的协议交互,如果没有xmlrpc扩展,建议使用PEAR::XML-RPC扩展。
我们这里主要是以XML-RPC来简单描述Web Service的交互过程,部分内容来自PHP手册,更详细的内容,读者可以参考手册。
二、安装xmlrpc扩展:
如果你的系统中没有安装xmlrpc的php扩展,那么请正确安装。
在Windows平台下,首先把PHP安装目录下的扩展php_xmlrpc.dll放到C:\Windows或者C:\Winnt目录下,(PHP4的扩展在C:\php\extensions目录中,PHP5的扩展在C:\php\ext目录中。dll扩展文件的具体安装目录视你的php安装目录而定,此处仅为示例说明),同时在C:\Windows\php.ini或者C:\Winnt\php.ini中把extension=php_xmlrpc.dll前面的分号";"去掉,然后重启Web服务器后查看phpinfo()有没有XML-RPC项目就能够确定是否已经正确安装xmlrpc扩展。
在Unix/Linux平台下,如果没有安装xmlrpc扩展,请在重新编译PHP,在configure的时候请加入 --with-xmlrpc 选项,然后查看phpinfo()看是否正常安装xmlrpc。
(注意:以下操作都是建立在xmlrpc扩张正常安装前提下,请务必正确安装。)
三、XML-RPC工作原理:
XML-RPC大致就是整个过程就是使用XML来进行通信。首先构造一个RPC 服务器端用来出来从RPC客户端传递过来的使用XML封装的请求,并且把处理结果通过XML的形式返回给RPC客户端,客户端就去分析XML获取自己需要的数据。
XML-RPC的服务器端必须有现成的函数提供给客户端调用,并且客户端提交的请求中的函数和方法必须和服务器端的一致,否则将无法获取所需要的结果。
下面我进行简单的代码来描述整个过程。
四、XML-RPC实践:
服务器端使用xmlrpc_server_create函数产生一个服务器端,然后把需要需要暴露的RPC调用接口进行注册,接受RPC客户端POST过来的XML数据,然后进行处理,处理结果通过XML的形式显示给客户端。
rpc_server.php文件代码如下:
* 函数:提供给RPC客户端调用的函数
* $method 客户端需要调用的函数
* $params 客户端需要调用的函数的参数数组
* 返回:返回指定调用结果
function rpc_server_func($method, $params) {
$parameter = $params[0];
if ($parameter == "get")
$return = ''This data by get method'';
$return = ''Not specify method or params'';
//产生一个XML-RPC的服务器端
$xmlrpc_server = xmlrpc_server_create();
//注册一个服务器端调用的方法rpc_server,实际指向的是rpc_server_func函数
xmlrpc_server_register_method($xmlrpc_server, "rpc_server", "rpc_server_func");
//接受客户端POST过来的XML数据
$request = $HTTP_RAW_POST_DATA;
//执行调用客户端的XML请求后获取执行结果
$xmlrpc_response = xmlrpc_server_call_method($xmlrpc_server, $request, null);
//把函数处理后的结果XML进行输出
header(''Content-Type: text/xml'');
echo $xmlrpc_
//销毁XML-RPC服务器端资源
xmlrpc_server_destroy($xmlrpc_server);
至此服务器端就构造好了,那么再构造我们的RPC客户端。客户端大致通过Socket访问XML-RPC服务器端的80端口,然后把需要调用的RPC接口封装到XML里,通过POST请求提交给RPC服务器端,最后获取服务器端返回结果。
rpc_client.php文件代码如下:
* 函数:提供给客户端进行连接XML-RPC服务器端的函数
* $host 需要连接的主机
* $port 连接主机的端口
* $rpc_server XML-RPC服务器端文件
* $request 封装的XML请求信息
* 返回:连接成功成功返回由服务器端返回的XML信息,失败返回false
function rpc_client_call($host, $port, $rpc_server, $request) {
//打开指定的服务器端
$fp = fsockopen($host, $port);
//构造需要进行通信的XML-RPC服务器端的查询POST请求信息
$query = "POST $rpc_server HTTP/1.0\nUser_Agent: XML-RPC Client\nHost: ".$host."\nContent-Type: text/xml\nContent-Length: ".strlen($request)."\n\n".$request."\n";
//把构造好的HTTP协议发送给服务器,失败返回false
if (!fputs($fp, $query, strlen($query)))
$errstr = "Write error";
//获取从服务器端返回的所有信息,包括HTTP头和XML信息
$contents = '''';
while (!feof($fp))
$contents .= fgets($fp);
//关闭连接资源后返回获取的内容
fclose($fp);
//构造连接RPC服务器端的信息
$host = ''localhost'';
$port = 80;
$rpc_server = ''/~heiyeluren/rpc_server.php'';
//把需要发送的XML请求进行编码成XML,需要调用的方法是rpc_server,参数是get
$request = xmlrpc_encode_request(''rpc_server'', ''get'');
//调用rpc_client_call函数把所有请求发送给XML-RPC服务器端后获取信息
$response = rpc_client_call($host, $port, $rpc_server, $request);
//分析从服务器端返回的XML,去掉HTTP头信息,并且把XML转为PHP能识别的字符串
$split = '''';
$xml = explode($split, $response);
$xml = $split . array_pop($xml);
$response = xmlrpc_decode($xml);
//输出从RPC服务器端获取的信息
print_r($response);
大致我们上面的例子就是提交一个叫做rpc_server的方法过去,参数是get,然后获取服务器端的返回,服务器端返回的XML数据是:
&?xml version="1.0" encoding="iso-8859-1"?&
&methodResponse&
&string&This data by get method&/string&
&/methodResponse&
那么我们再通过xmlrpc_decode函数把这个XML编码为PHP的字符串,就能够随意处理了,至此整个Web Service交互完成。
五、总结:
不管是XML-RPC也好,SOAP也罢,只要能够让我们稳定、安全的进行远程过程的调用,完成我们的项目,那么就算整个Web Service就是成功的。另外,如果可以的话,也可以尝试使用PEAR中的XML-RPC来实现上面类似的操作,说不定会更简单,更适合你使用。有兴趣的读者可以尝试去完成。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 redis历史 的文章

 

随机推荐