server 端同上篇用 perl 寫的,client 端改用 php 來 call。
參考
PHP XML-RPC 的使用(有效)
PHP XML-RPC Client(encode_xmlrpc) (有效)
view plain
PHP:
/**
* Debian: apt-get install php5-xmlrpc php5-curl
*/
/**
The MIT License
Copyright (c) 2007
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, [...]
範例包含 server、client,執行前先使用 ppm 安裝「Frontier-RPC」、「Frontier-Daemon-Forking」modules。
參考「用 XML-RPC 開發 Web 服務: 針對 Perl 的 XML-RPC 入門」
Server
view plain
PERL:
#!/usr/bin/perl
# sum() server
use strict;
use warnings;
use Frontier::Daemon;
my $d = Frontier::Daemon->new(
methods => {
sum => \&sum,
},
LocalAddr => '127.0.0.1',
LocalPort => 1234,
);
sub sum {
my ($arg1, $arg2) = @_;
return $arg1 + $arg2;
}
Client
view plain
PERL:
#!/usr/bin/perl
# Testing sum()
use strict;
use warnings;
use Frontier::Client;
my $url = "http://127.0.0.1:1234/RPC2";
my @args = (2,5);
my $client = Frontier::Client->new( [...]