Over a million developers have joined DZone.

Read Rpc List From File And Ping All - For Your Blog!

·
This is a PHP5-based XML-RPC ping script. It reads a one-column fully qualified URL-list from a file ($pingListFile). Such a script is extremely useful for bloggers ;-)

Please, edit the variables at the top of the file to fit your needs.


 
   // delimiter is an ASCII-linebreak)
   $fp=fopen($pingListFile,"r");
   while ( ! feof( $fp) )
   {
      $line = trim(fgets( $fp, 4096));
      // get the hostname
      $host=$line; // Make a copy of $line
      $host=preg_replace('/^.*http:\/\//','',$host); // Delete anything before http://
      $host=preg_replace('/\/.*$/','',$host); // Delete anything after behind the hostname

      // get the path 
      $path=$line; // Make another copy of $line
      $path=preg_replace('/^.*http:\/\/[a-zA-Z0-9\-_\.]*\.[a-zA-Z]{1,3}\//','',$path,-1,$replacementCount); // Delete anything before the path
      if(!$replacementCount) $path=''; // if there was no replacement (i.e. no explicit path), act appropiately
      if($host) $myList[$host]=$path;
   }
   echo "

Ping process started

"; echo "

Reading URLs from file $pingListFile: "; echo count($myList)." urls read.

"; // Use DOM to create the XML-File $xml= new DOMDocument('1.0'); $xml->formatOutput=true; $xml->preserveWhiteSpace=false; $xml->substituteEntities=false; // Create the xml structure $methodCall=$xml->appendChild($xml->createElement('methodCall')); $methodName=$methodCall->appendChild($xml->createElement('methodName')); $params=$methodCall->appendChild($xml->createElement('params')); $param[1]=$params->appendChild($xml->createElement('param')); $value[1]=$param[1]->appendChild($xml->createElement('value')); $param[2]=$params->appendChild($xml->createElement('param')); $value[2]=$param[2]->appendChild($xml->createElement('value')); // Set the node values $methodName->nodeValue="weblogUpdates.ping"; $value[1]->nodeValue=$blogTitle; $value[2]->nodeValue=$blogUrl; $xmlrpcReq = $xml->saveXML(); // Write the document into a string $xmlrpcLength = strlen( $xmlrpcReq ); // Get the string length. echo "Here's the xml-message I generated (size: $xmlrpcLength bytes):"; echo "\n
\n";
   echo htmlentities($xmlrpcReq);
   echo "
"; echo "
"; // Proceed every link read from file foreach ( $myList as $host => $path) { if($showDebugInfo) echo "
"; echo "
Pinging host: $host "; $httpReq = "POST /" . $path . " HTTP/1.0\r\n"; $httpReq .= "User-Agent: " . $userAgent. "\r\n"; $httpReq .= "Host: " . $host . "\r\n"; $httpReq .= "Content-Type: text/xml\r\n"; $httpReq .= "Content-length: $xmlrpcLength\r\n\r\n"; $httpReq .= "$xmlrpcReq\r\n"; echo "
"; if($showDebugInfo) { echo "
Request:
".htmlentities($httpReq)."
"; echo "Answer:
";
      }

      // Actually, send ping
      if ( $pinghandle = @fsockopen( $host, 80 ) )
      {
	 @fputs( $pinghandle, $httpReq );
	 while ( ! feof( $pinghandle ) )
	 { 
	    $pingresponse = @fgets( $pinghandle, 128 );
	    if($showDebugInfo) echo htmlentities($pingresponse);
	 }
	 @fclose( $pinghandle );
      }
      if($showDebugInfo) echo "
"; } echo "
"; echo "

FINISHED

"; ?>
Here's an example input-file (pinglist.txt): http://blogsearch.google.com/ping/RPC2 http://rpc.technorati.com/rpc/ping http://www.newsisfree.com/xmlrpctest.php http://ping.bitacoras.com http://ping.blo.gs/ http://ping.bloggers.jp/rpc/ http://api.moreover.com/ping http://api.my.yahoo.com/RPC2 http://api.my.yahoo.com/rss/ping http://www.bitacoles.net/ping.php http://bitacoras.net/ping http://blogdb.jp/xmlrpc http://www.blogdigger.com/RPC2 http://www.blogoole.com/ping/ http://www.blogoon.net/ping/
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}