XML RPC With The Incutio PHP Librar: A Beginner's Guide: Incutio Home Scripts Contact Manual Index
XML RPC With The Incutio PHP Librar: A Beginner's Guide: Incutio Home Scripts Contact Manual Index
XMLRPCwiththeIncutioPHPLibrar :ABeginner'sGuide
XMPRPCstandsforXMLRemoteProcedureCalling.Itisaprotocolformakingandreceivingprocedurecalls overtheinternet. WhatthismeansisthatdifferentcomputerscanuseXMLRPCto"askeachotherquestions".UsingXMLRPC isjustlikemakingafunctioncallinPHP,onlythecomputerthatexecutesthefunctioncouldbethousandsofmiles away. WiththeIncutioXMLRPCLibrary,makingandreceivingXMLRPCrequestsisalmostassimpleascalling nativePHPfunctions.Here'ssomesamplecode,whichcallsafunctionentitled"test.getTime"onoursimple demonstrationserver:
$client=newIXR_Client('http://scripts.incutio.com/xmlrpc/simpleserver.php') $client>query('test.getTime') print$client>getResponse() //Printsthecurrenttime,accordingtoourwebserver
Witherrorchecking,theabovecodelookslikethis:
$client=newIXR_Client('http://scripts.incutio.com/xmlrpc/simpleserver.php') if(!$client>query('test.getTime')){ die('Anerroroccurred'.$client>getErrorCode().":".$client>getErrorMessage()) print$client>getResponse()
Youcanalsosendargumentsalongwithyourqueries:
$client=newIXR_Client('http://scripts.incutio.com/xmlrpc/simpleserver.php') if(!$client>query('test.add',4,5)){ die('Anerroroccurred'.$client>getErrorCode().":".$client>getErrorMessage()) print$client>getResponse() //Prints'9'
Argumentsarenotlimitedtosimplevalues.Youcansendstringsandarraysaswell:
$client=newIXR_Client('http://scripts.incutio.com/xmlrpc/simpleserver.php') if(!$client>query('test.addArray',array(3,5,7))){ die('Anerroroccurred'.$client>getErrorCode().":".$client>getErrorMessage()) print$client>getResponse() //Prints'3+5+7=15'
WritinganXMLRPCserverissimpleaswell.Here'sthefullcodeforsimpleserver.php:
scripts.incutio.com/ mlrpc/beginners.php 1/3
7/10/12
WritinganXMLRPCserverissimpleaswell.Here'sthefullcodeforsimpleserver.php:
<?php include('IXR_Library.inc.php') /*Functionsdefiningthebehaviouroftheserver*/ functiongetTime($args){ returndate('H:i:s') functionadd($args){ return$args[0]+$args[1] functionaddArray($array){ $total=0 foreach($arrayas$number){ $total+=$number returnimplode('+',$array).'='.$total /*CreatetheserverandmaptheXMLRPCmethodnamestotherelevantfunctions*/ $server=newIXR_Server(array( 'test.getTime'=>'getTime', 'test.add'=>'add', 'test.addArray'=>'addArray' )) ?>
Prett simplehuh? TheIncutioXMLRPCLibrar candoalotmorethanisdemonstratedabove.Besuretoreadthemanualfor moreinformation. Scripts ScriptsHome PHPXMLRPCLibrar PHPAma onSearch PHPGoogleWebAPI incDirector ssLinks
scripts.incutio.com/ mlrpc/beginners.php
2/3
7/10/12
Design,Content,Images 20022012IncutioLimited|W3CXHTML1.0
scripts.incutio.com/ mlrpc/beginners.php
3/3