Debugging a PHP XMLRPC Service with Xdebug and Curl

Standard

curl -i -X POST \
   -H "Content-Type:application/xml" \
   -d \
'<?xml version="1.0"?>
<methodCall>
<methodName>sample.sumAndDifference</methodName>
<params>
<param><value><int>1</int></value></param>
<param><value><int>2</int></value></param>
</params>
</methodCall>' \
 'http://localhost/xmlrpc_server.php?XDEBUG_SESSION_START=sublime.xdebug'

xmlrpc_server.php

<?xml version="1.0"?>
<methodResponse>
<params>
<param>
<value><struct>
<member><name>sum</name>
<value><int>3</int></value>
</member>
<member><name>difference</name>
<value><int>-1</int></value>
</member>
</struct></value>
</param>
</params>
</methodResponse>

转XML-RPC范例

Standard

xmlrpc_client.php

<html>
<head>
<title>XML-RPC PHP Demo</title>
</head>
<body>
<h1>XML-RPC PHP Demo</h1>
<?php
include './xmlrpc.inc';
// Make an object to represent our server.
$server = new xmlrpc_client('/xmlrpc_server.php', 'www.test.com', 80);
 
// Send a message to the server.
$message = new xmlrpcmsg('sample.sumAndDifference',
                         array(new xmlrpcval(5, 'int'),
                               new xmlrpcval(3, 'int')));
$result = $server->send($message);
 
// Process the response.
if (!$result) {
    print "<p>Could not connect to HTTP server.</p>";
} elseif ($result->faultCode()) {
    print "<p>XML-RPC Fault #" . $result->faultCode() . ": " .
        $result->faultString();
} else {
    $struct = $result->value();
    $sumval = $struct->structmem('sum');
    $sum = $sumval->scalarval();
    $differenceval = $struct->structmem('difference');
    $difference = $differenceval->scalarval();
    print "<p>Sum: " . htmlentities($sum) .
        ", Difference: " . htmlentities($difference) . "</p>";
}
?>
</body></html>

xmlrpc_server.php

<?php
include './xmlrpc.inc';
include './xmlrpcs.inc';
 
function sumAndDifference ($params) {
    // Parse our parameters.
    $xval = $params->getParam(0);
    $x = $xval->scalarval();
    $yval = $params->getParam(1);
    $y = $yval->scalarval();
 
    // Build our response.
    $struct = array('sum' => new xmlrpcval($x + $y, 'int'),
                    'difference' => new xmlrpcval($x - $y, 'int'));
    return new xmlrpcresp(new xmlrpcval($struct, 'struct'));
}
 
// Declare our signature and provide some documentation.
// (The PHP server supports remote introspection. Nifty!)
$sumAndDifference_sig = array(array('struct', 'int', 'int'));
$sumAndDifference_doc = 'Add and subtract two numbers';
 
new xmlrpc_server(array('sample.sumAndDifference' =>
                        array('function' => 'sumAndDifference',
                              'signature' => $sumAndDifference_sig,
                              'docstring' => $sumAndDifference_doc)));
?>

PHP Msgpack安装报错处理

Standard

libtool: Version mismatch error…

phpize –clean;
phpize;
rm aclocal.m4;
aclocal;
autoconf;
./configure;
make;
make install;

done!

ps:
MessagePack是一种新的基于二进制的对象序列化类库。它可以像JSON那样,在许多种语言之间交换结构对象;但是它比JSON更快速也更轻巧。

以下转载自:http://hi.baidu.com/yzkuang/blog/item/557e4f24423d8136c9955908.html

1.autoscan (autoconf): 扫描源代码以搜寻普通的可移植性问题,比如检查编译器,库,头文件等,生成文件configure.scan,它是configure.ac的一个雏形。
2.aclocal (automake):根据已经安装的宏,用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件 aclocal.m4中。aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configure.ac”
 
user input files   optional input     process          output files
================   ==============     =======          ============
 
                    acinclude.m4 - - - - -.
                                          V
                                      .-------,
configure.ac ------------------------>|aclocal|
                 {user macro files} ->|       |------> aclocal.m4
                                      `-------'
3.autoheader(autoconf): 根据configure.ac中的某些宏,比如cpp宏定义,运行m4,声称config.h.in
 
user input files    optional input     process          output files
================    ==============     =======          ============
 
                    aclocal.m4 - - - - - - - .
                                             |
                                             V
                                     .----------,
configure.ac ----------------------->|autoheader|----> autoconfig.h.in
                                     `----------'
4.automake: automake将Makefile.am中定义的结构建立Makefile.in,然后configure脚本将生成的Makefile.in文件转换为Makefile。如果在configure.ac中定义了一些特殊的宏,比如AC_PROG_LIBTOOL,它会调用libtoolize,否则它会自己产生config.guess和config.sub
 
user input files   optional input   processes          output files
================   ==============   =========          ============
 
                                     .--------,
                                     |        | - - -> COPYING
                                     |        | - - -> INSTALL
                                     |        |------> install-sh
                                     |        |------> missing
                                     |automake|------> mkinstalldirs
configure.ac ----------------------->|        |
Makefile.am  ----------------------->|        |------> Makefile.in
                                     |        |------> stamp-h.in
                                 .---+        | - - -> config.guess
                                 |   |        | - - -> config.sub
                                 |   `------+-'
                                 |          | - - - -> config.guess
                                 |libtoolize| - - - -> config.sub
                                 |          |--------> ltmain.sh
                                 |          |--------> ltconfig
                                 `----------'
5.autoconf:将configure.ac中的宏展开,生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。
 
user input files   optional input   processes          output files
================   ==============   =========          ============
 
                   aclocal.m4 - - - - - -.
                                         V
                                     .--------,
configure.ac ----------------------->|autoconf|------> configure ----->autoconfig.h,Makefile

《大话设计模式》装饰模式-穿什么场景-PHP版代码

Standard

装饰模式
穿什么场景

<?php
/**
 * 装饰模式 穿什么场景
 * @author 叶茂盛 anson.ye#gmail.com  http://yemaosheng.com
 */
interface Component{
        public function Show();
}
 
class Person implements Component{
        protected $_name;
 
        public function __construct($name){
                $this->_name = $name;
        }
        public function Show(){
                echo "装扮的".$this->_name;
        }
}
 
 
abstract class Finery implements Component{
        protected $_component;
        public function Decorate(Component $component){
                $this->_component = $component;
        }
        public function Show(){
                $this->_component->Show();
        }
}
class Sneakers extends Finery{
        public function Show(){
                echo "旅游鞋 ";
                parent::Show();
        }
}
class TShirts extends Finery{
        public function Show(){
                echo "T恤 ";
                parent::Show();
        }
}
class BigTrouser extends Finery{
        public function Show(){
                echo "垮裤 ";
                parent::Show();
        }
}
class Tie extends Finery{
        public function Show(){
                echo "领带 ";
                parent::Show();
        }
}
class Suit extends Finery{
        public function Show(){
                echo "西装 ";
                parent::Show();
        }
}
class LeatherShoes extends Finery{
        public function Show(){
                echo "皮鞋 ";
                parent::Show();
        }
}
class Main{
        public static function run(){
                $xc = new Person("小菜");
 
                $sk = new Sneakers();
                $ts = new TShirts();
                $bt = new BigTrouser();
 
                echo "装扮1:\n";
                $sk->Decorate($xc);
                $ts->Decorate($sk);
                $bt->Decorate($ts);
                $bt->Show();
 
                $dn = new Person("大鸟");
 
                $ti = new Tie();
                $si = new Suit();
                $ls = new LeatherShoes();
 
                echo "\n装扮2:\n";
                $ti->Decorate($dn);
                $si->Decorate($ti);
                $ls->Decorate($si);
                $ls->Show();
 
        }
}
Main::run();
?>
//php Decorator.php 
//装扮1:
//垮裤 T恤 旅游鞋 装扮的小菜
//装扮2:
//皮鞋 西装 领带 装扮的大鸟

转载请注明出处 http://yemaosheng.com