XML-RPC pinging (google and others)

11,681

Solution 1

As far as you're concerned to do the XML-RPC request (Example #1).

If you follow the specification of a pingback, it would look like this:

$sourceURI = 'http://example.com/';
$targetURI = 'http://example.com/';
$service = 'http://blogsearch.google.com/ping/RPC2';

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

Which would give you the following output:

Array
(
    [flerror] => 
    [message] => Thanks for the ping.
)

Generally, if you don't know which method you call, you can also try XML-RPC Introspection - but not all XML-RPC servers offer that.


You asked in a comment:

According to specs, $targetURI should be: "The target of the link on the source site. This SHOULD be a pingback-enabled page". How can I make pingback enabled page, or more important, what is that actually?

A pingback enabled site is a website that announces an XML-RPC pinbback service as well. That's done with the HTMl <link> element in the <head> section. Example:

<link rel="pingback" href="http://hakre.wordpress.com/xmlrpc.php" />

The href points to an XML-RPC endpoint that has the pingback.ping method available.

Or it's done by sending a specifc HTTP response header:

X-Pingback: http://charlie.example.com/pingback/xmlrpc

See pingback-enabled resource.

So if you ping others, others should be able to ping you, too.

Solution 2

Ummm, I think we should use weblogUpdates.ping or weblogUpdates.extendedPing instead of pingback.ping to ping a site about new content.

pingback.ping is for a new link from one site to another, not for new content.

Solution 3

I think you should use weblogUpdates.extendedPing with google blog search, weblogs, Pingomatic and weblogUpdates.ping for other server. I created a ping tool but some server return an error with http and https, i cannot give a bug Online rpc xml ping

Share:
11,681
dario111cro
Author by

dario111cro

Updated on June 07, 2022

Comments

  • dario111cro
    dario111cro about 2 years

    I am trying to ping (SEO tactic called "ping" is used for new content to get robots index it faster) Google in PHP. Only thing I know is that I need to send my request to following url: http://blogsearch.google.com/ping/RPC2

    Probably I can use PHP XML-RPC functions. I don't know how to format my request and which method to use.

  • dario111cro
    dario111cro over 12 years
    I should easily make request by following PHP documentation. I don't know method or which variables I need to send. I would really appriciate if you can post link to google's documentation, since I can't find it.
  • hakre
    hakre over 12 years
    @dario111cro: I added the specs and extended the example code.
  • hakre
    hakre over 12 years
    @dario111cro: You're welcome. Those specs weren't @ google, and as I've seen they removed the reference to it from their site, they had some kind of their own API in the past, see web.archive.org/web/20091119080527/http://www.google.co.kr/h‌​elp/…
  • dario111cro
    dario111cro over 12 years
    According to specs, $targetURI should be: "The target of the link on the source site. This SHOULD be a pingback-enabled page". How can I make pingback enabled page, or more important, what is that actually?
  • hakre
    hakre over 12 years
    @dario111cro: I extended the answer again.