Ping a server in PHP

Status
Not open for further replies.

bubbles

Domainers...
Apr 11, 2007
859
27
0
So I have an RSS feed that I want to ping blogs with when I update the rss fee. I don't really know if its as easy as include()ing the url or if I have to take it one step farther.

When I searched google I didn't find what I was looking for. I was hoping someone could provide me with some example code of how to ping a service such as blogsearch.google.com to notify them my rss feed is updated.
 


You need to use XML::RPC or you can hack the querystring on some of the ping services.
 
I did the query string thing with pingomatic, but then their server was having problems today and the request was timing out.

I'll look into XML:RPC thanks.
 
Heres on Ive used:

Code:
<?

$response = weblogUpdates_ping('SITE_NAME', 'FEED_URL', 'rpc.pingomatic.com');

function weblogUpdates_ping($blog_title, $blog_url, $rpc_host, $rpc_page='/', $rpc_port='80')
{
	$xml_rpc = '<?xml version="1.0" encoding="utf-8"?>'."\r\n";
	$xml_rpc .= '<methodCall>'."\r\n";
	$xml_rpc .= '	<methodName>weblogUpdates.ping</methodName>'."\r\n";
	$xml_rpc .= '	<params>'."\r\n";
	$xml_rpc .= '		<param>'."\r\n";
	$xml_rpc .= '			<value>'.$blog_title.'</value>'."\r\n";
	$xml_rpc .= '		</param>'."\r\n";
	$xml_rpc .= '		<param>'."\r\n";
	$xml_rpc .= '			<value>'.$blog_url.'</value>'."\r\n";
	$xml_rpc .= '		</param>'."\r\n";
	$xml_rpc .= '	</params>'."\r\n";
	$xml_rpc .= '</methodCall>'."\r\n";

	$xml_rpc_length = strlen($xml_rpc);

	$http_request = 'POST '.$rpc_page.' HTTP/1.0'."\r\n";
	$http_request .= 'User-Agent: sebastienguillon.com'."\r\n";
	$http_request .= 'Host: '.$rpc_host."\r\n";
	$http_request .= 'Content-Type: text/xml'."\r\n";
	$http_request .= 'Content-length: '.$xml_rpc_length."\r\n\r\n";
	$http_request .= $xml_rpc."\r\n";
	
	/* Décommentez la ligne suivante pour afficher la requête XML-RPC */
	//echo '<p>Requête XML-RPC :</p><pre>'.htmlentities($http_request).'</pre>';

	$theSock = fsockopen($rpc_host, $rpc_port);
	if($theSock)
	{
		fwrite($theSock,$http_request);
		stream_set_blocking($theSock,1);

		while(!feof($theSock))
		{
			$buf .= fgets($theSock,128);
		}
		fclose($theSock);
		/* Décommentez la ligne suivante pour afficher la réponse à la requête XML-RPC */
		return '<p>XML-RPC Respons:</p>'."\r\n\r\n".'<pre>'.htmlentities($buf).'</pre>';
	}
}
?><html><body>
<h1>Responses:</h1>
<?php echo $response1; ?>
</body></html>
 
  • Like
Reactions: illusion
$blog_title is the title of my blog
$blog_url is the url of my blog
Where can I put my blog rss feed?
 
$blog_url should be the URL of your feed.

Here is an example call:
Code:
$response = weblogUpdates_ping('My Kick-Ass Blog', 'http://www.kickassblog.com/feed.xml', 'rpc.pingomatic.com');
 
Thanks nis for this.

Seems to work but I am not getting any response echoed back following the ping with this script.
Same for you?
 
Status
Not open for further replies.