You can use XML-RPC to allow different platform software to interact with each other, we assume that using PHP as the foreground (client), Python as a service backstage, between XML-RPC invoke the services provided by Python. Examples are as follows:
1. PHP Client
<?php
xmlrpc_client.php
XML-RPC Client demo program
Require (' xmlrpc.inc ');
$xmlrpc _internalencoding= ' UTF-8 ';
Create a client object with three arguments in the path, hostname, port
# $s =new xmlrpc_client ('/testxml/xmlrpc_server.php ', ' localhost ', 80);
$s =new xmlrpc_client ('/', ' localhost ', 8888);
Create Xmlrpcval object, which allows the encoding of our variable
Create a Xmlrpcval object that encodes our PHP variables into XML-RPC-required forms
# $inputString =new Xmlrpcval (' World Triumph ', ' string ');
$inputString = Php_xmlrpc_encode (' Victory World ');
Create an array of parameters
Although we have only one argument, we still want to convert the form of an array, because the second parameter of xmlrpcmsg is a parameter table
$parameters =array ($inputString);
Create the Message Object
Create an XML-RPC message with parameters for the remote method name and parameter table
$msg =new xmlrpcmsg (' echostring ', $parameters);
$s->request_charset_encoding = ' utf-8 ';
Send the message and get the response
Sends a message, the return value $RSP to a Xmlrpcresp object, which contains the following three methods:
FaultCode () error code, if successful will return 0
FaultString () error message
Value () returns the Xmlrpcval object form, which needs to be decoded before PHP is used
$s->debug = true;
$RSP = $s->send ($msg);
Check for errors
if ($rsp->faultcode () ==0) {
Decode the response to a PHP type
The Xmlrpc_decode () function is used to decode the Xmlrpcval object
$response =php_xmlrpc_decode ($RSP->value ());
Print results
print ' <pre> ';
Var_dump ($response);
print ' </pre> ';
} else {
Print Errors
print ' Error: '. $RSP->faultcode (). $RSP->faultstring (). <br> ';
}
Show Messages
And then we'll look at the contents of the message.
$msg->createpayload ();
print ' request:<xmp> '. $msg->payload. " </xmp> ';
print ' response:<xmp> '. $RSP->serialize (). " </xmp> ';
?>
2, Python service side
#-*-coding:gb2312-*-
Import Simplexmlrpcserver
#定义自己的CMS类
Class Mycms:
def getversion (self