dario111cro
dario111cro

Reputation: 805

XML-RPC pinging (google and others)

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.

Upvotes: 8

Views: 13330

Answers (3)

NguyenNgocPhuong
NguyenNgocPhuong

Reputation: 437

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

Upvotes: 1

Taha Jahangir
Taha Jahangir

Reputation: 4902

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.

Upvotes: 1

hakre
hakre

Reputation: 198204

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.

Upvotes: 8

Related Questions