Search code examples
phpxml-rpcpingback

PHP XMLRPC server without extension


I'm trying to create a pingback script for our website, however 1&1 does not have the XMLRPC extension that we require installed.

Are there any alternatives to creating a pingback/trackback script without the need of this extension - and are there any demos?


Solution

  • phpxmlrpc

    An old Php implementation and it seem to be abandoned, but you can see how to use it to send pingbacks or receive them in this blogpost.

    Zend

    There is a pure php implementation of XML-RPC client and server in the Zend framework, you can use it to call or implement a pingback service, and it's well documented. If you don't want to use the full framework only as a component library, just download the framework, extract the lib/Zend from it to a directory and include the component's top level file. (you might want to set up autoloading for convenience)

    The pingback service description is here.

    If you have that set up, you can go to this blogpost for pointers for client/server codes, i give you some examples with the Zend classes (the post uses the xmlrpc extension)

    Sending pingbacks:

    require_once 'Zend/XmlRpc/Client.php'; // path to the framework files
    try {
        $client = new Zend_XmlRpc_Client('<pingback service url>');
        $client->call('pingback.ping', array('<source uri>', '<target uri>'));
    } catch (Exception $e) {
       // error handling
    }
    

    The service url will be in the blog post's http header, or in a meta tag, described in the pingback documentation.

    Pingback service skeleton

    class PingBackService {
        public function ping($source, $target) {
            $source_url = $source[0];
            $target_url = $target[0];
    
            // validate parameters here, see http://www.quietearth.us/articles/2006/10/30/Coding-your-own-blog-Pingback-in-php for pointers
    
            return 'Pingback registered. May the force be with you';
        }
    }
    require_once 'Zend/XmlRpc/Server.php';
    try {
        $server = new Zend_XmlRpc_Server();
        $server->setClass('PingBackService', 'pingback');
        echo $server->handle();
    } catch (Exception $e) {
        // handle errors
    }