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, extract it and move the file libs/ 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','', 80);                $message = new xmlrpcmsg("", array(new xmlrpcval(""),         new xmlrpcval("")));        // 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:  

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.

Det er stengt for kommentarer.