Hi Guys,

I am trying to set up a script that pings (weblogUpdates.ping) feedburner at http://ping.feedburner.com/ when I post new content.

I have been looking at tutorials all day, and this is what I have come up with:

$method = "weblogUpdates.ping";
$params = array("MySiteName","url","url","none");

$request = xmlrpc_encode_request($method,$params);
$context = stream_context_create(array('http' => array(
    'method' => "POST",
    'header' => "Content-Type: text/xml",
    'header' => "host: ping.feedburner.com",
    'header' => "Content-Length: 250",
    'content' => $request
)));
$file = file_get_contents("http://ping.feedburner.com", false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
    trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
    print_r($response);
}

I would like some advice as to whether or not this is the best way to go, will it even work, and if not, why not? What better ways are there? and so on.

When I try to run it it says: Call to undefined function xmlrpc_encode_request() in /home/writeabo/public_html/pingfeed.php on line 5

I guess this means my PHP doesn't have the xml-rpc enabled. Any ideas what I should ask of my host in the support email to get this sorted?

Thanks in advance.

    the documentation has a big 'this is experimental' warning for [man]xmlrpc_encode_request[/man]. That might be a good reason to consider something else. On the other hand, your code is nice and short and what its function is pretty clear. You shouldn't hesitate to ask your host to install or enable XML-RPC in the PHP module on the server. If he/she is confused, send this url:
    http://us2.php.net/manual/en/book.xmlrpc.php

      Thanks for the tip with what to ask of my hosting company. That email is now sent and I'm happier.

      However, almost ever function in the XML-RPC library of PHP has the same warning. I really want to use PHP though, rather than learn CGI or PERL etc.

      However, if you know PERL or CGI and can put me onto a simple tutorial to do the task I want, I'm open to give it a try.

        I'm not entirely sure what the task is and I'm not familiar with perl or cgi. I'm guessing you got some sample code from somewhere as it looks very specific.

        If XML-RPC works, your job is done. If it doesn't, worry about it then, right?

          Your right. I did take the code from somewhere and made minor changes to what I hope will suit my purpose. I was really hoping to find someone on here who could tell me if I was on the right track. Thanks for your input.

            I do think you are on the right track if feedburner supports xml RPC calls. If they don't, it won't work at all.

              Hi Guys,

              I tried it and got the following output:

              Array ( [message] => Exception processing ping request [flerror] => 1 )

              Any ideas?

                That looks like your PHP is working fine but there was a problem with your interaction with the feedburner site.

                Maybe try 'method' => "get" instead? I googled around a bit and it looks like that worked for somebody.

                Also, there is a feedburner help group in google groups:
                http://groups.google.com/group/feedburner

                Maybe try posting there.

                  Hooray. I have gotten it working. paint me chuffed.

                    'paint me chuffed' 😃

                    Care to share the solution with us?

                      Hi,

                      Yeah, sorry. I am that used to coming on here and someone helps me out with a solution, then I just say, that works, thanks, and mark the thread resolved.

                      Anyway, once I got it working, I decided to go for an extended ping, which is only a couple of extra items in the $parameters array, and of course a change to the $method var. Here is the solution:

                      <?php
                      $method = "weblogUpdates.extendedPing";
                      $params = array("My site","homepage-url","changes-url","feed-url");
                      $request = xmlrpc_encode_request($method,$params);
                      $context = stream_context_create(array('http' => array(
                          'method' => "POST /RPC2 HTTP/1.0",
                          'header' => "Content-Type: text/xml",
                      		'header' => "Content-Length: 250",
                      		'header' => "Host: ping.feedburner.com",
                      		'header' => "User-Agent:LBaileysRPCPinger",
                          'content' => $request
                      )));
                      $file = file_get_contents("http://ping.feedburner.com/", false, $context);
                      $response = xmlrpc_decode($file);
                      if (xmlrpc_is_fault($response)) {
                          trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
                      } else {
                          print_r($file);
                      }
                      ?>
                      

                      I have actually changed it, so that the $response is encoded and put onto a query string, but running that, shows you it is working. changing the 'Host' header to rpc.weblogs.com and also the url in file_get_contents to the same, gives a more detailed success message.

                        One other thing you might want to do is make your content-length value truly reflect the length of your content. I doubt it's 250. Perhaps try strlen($request) ?

                          Write a Reply...