PHP code example of devedge / xmlrpc-server

1. Go to this page and download the library: Download devedge/xmlrpc-server library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devedge / xmlrpc-server example snippets



    
    // use autoloading for the composer stuff
    vedge\XmlRpc\Server();

    
    // create an instance of your service
    // a service instance should have the methods that can be called through the xmlrpc interface.  
    $service = new Example\MyService();
    
    // create an instance of Devedge\XmlRpc\Server\Handlers\SimpleHandler. This class implements the
    // handler interface and allows to register any regular object to be used for handling the requests
    // simple handler will expose all public methods that don't start with __ towards the xmlrpc interface
    // make sure you only have methods that you actually want exposed!
    // the second parameter is a "namespace", expressing that all xmlrpc calls starting with "example." 
    // will be handled by this handler. 
    $handler = new Devedge\XmlRpc\Server\Handlers\SimpleHandler($service, "example")
    
    // as Devedge\XmlRpc\Server\Handlers\SimpleHandler implements the handler interface, the handler instance
    // can be registered as a handler with the server.
    // the server allows to register more than one handler (as long as they use different "namespaces"), and 
    // if a handler carries the namespace "default" it will also be used for methods that are called through xmlrpc
    // without a namespace set
    $server->registerHandler($handler);
    
    // lets be nice and set an xml content header.
    header("Content-Type: text/xml");
    
    // the handle method takes xmlrpc methodCall xml, and executes the handling
    // whatever return value the method of service is will be serialized as an 
    // xmlrpc answer, and available as return value of handle.
    echo $server->handle(file_get_contents('php://input'));