XML-RPC pinging (google and others)

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.

Tags:

Php

Xml

Seo

Xml Rpc