Implementing ping with phpxmlrpc in CakePHP

On of the latest things on my to-do list has been implementing a ping function in my CakePHP blog. I was hoping to find some code to copy and paste directly from CakePHP Google Group, but it seems that none has done it yet, and I ended up doing it myself.

This is how I did it:

  1. Download the XMLRPC PHP class from http://sourceforge.net/projects/phpxmlrpc/, extract it and move the file libs/xmlrpc.inc into app/vendors. Remember to change the fileextension to .php
  2. Include the file by adding this in the start of your controller: 
    vendor('xmlrpc');class PostsController extends AppController {
  3. Now create a separat ping function: function ping() {        // Make an object to represent our server.        $server = new xmlrpc_client('/rpc/ping','rpc.technorati.com', 80);                $message = new xmlrpcmsg("weblogUpdates.ping", array(new xmlrpcval("Gersh.no"),         new xmlrpcval("http://www.gersh.no")));        // Send a message to the server.                $result = $server->send($message);        if (!$result || $result->faultCode()) return(false);        else return(true);            }
  4.  Call this function whenever you want to ping and update or change with:  
    $this->ping();

What is ping?

any blog authoring tools automatically ping one or more servers each time the blogger creates a new post (or updates an old one.) That is, the tool sends an XML-RPC signal to one or more “ping servers,” which can then generate a list of blogs that have new material.

(from wikipedia):

Om Gerhard Sletten

Gerhard liker fisk.
Dette innlegget ble publisert i Computer. Bokmerk permalenken.

En kommentar til Implementing ping with phpxmlrpc in CakePHP

  1. Alex sier:

    thanx for that script…
    i hopeit will work fine, i didn´t test it yet, but bookmarked it, so i can use it later!

Legg igjen et svar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *

*

Du kan bruke disse HTML-kodene og -egenskapene: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>