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.
1
2 <?php
3 // Please, edit these variables to your needs
4
5 $blogTitle="Title Of your blog";
6 $blogUrl="http://www.yourblog.url/";
7 $pingListFile="pinglist.txt";
8 $showDebugInfo=FALSE; // Do you want verbose output?
9
10 // Stop editing here
11
12 // PingRPC.php
13 //
14 // 2007 by Sascha Tayefeh
15 // http://www.tayefeh.de
16 //
17 // This is a PHP5-based XML-RPC ping script. It reads a one-column
18 // fully qualified URL-list from a file ($pingListFile). Here is
19 // an example how this file must look like:
20 // ----------------------
21 // http://rpc.icerocket.com:10080/
22 // http://rpc.pingomatic.com/
23 // http://rpc.technorati.com/rpc/ping
24 // http://rpc.weblogs.com/RPC2
25 // ----------------------
26
27 $replacementCount=0;
28 $userAgent="pingrpc.php by tayefeh";
29
30 // Read pinglist file. Must contain one fully qualified URL
31 // (e.g: http://rpc.technorati.com/rpc/ping) PER LINE (->
32 // delimiter is an ASCII-linebreak)
33 $fp=fopen($pingListFile,"r");
34 while ( ! feof( $fp) )
35 {
36 $line = trim(fgets( $fp, 4096));
37 // get the hostname
38 $host=$line; // Make a copy of $line
39 $host=preg_replace('/^.*http:\/\//','',$host); // Delete anything before http://
40 $host=preg_replace('/\/.*$/','',$host); // Delete anything after behind the hostname
41
42 // get the path
43 $path=$line; // Make another copy of $line
44 $path=preg_replace('/^.*http:\/\/[a-zA-Z0-9\-_\.]*\.[a-zA-Z]{1,3}\//','',$path,-1,$replacementCount); // Delete anything before the path
45 if(!$replacementCount) $path=''; // if there was no replacement (i.e. no explicit path), act appropiately
46 if($host) $myList[$host]=$path;
47 }
48 echo "<h1>Ping process started</h1>";
49
50 echo "<p>Reading URLs from file $pingListFile: ";
51 echo count($myList)." urls read.</p>";
52
53 // Use DOM to create the XML-File
54 $xml= new DOMDocument('1.0');
55 $xml->formatOutput=true;
56 $xml->preserveWhiteSpace=false;
57 $xml->substituteEntities=false;
58
59 // Create the xml structure
60 $methodCall=$xml->appendChild($xml->createElement('methodCall'));
61 $methodName=$methodCall->appendChild($xml->createElement('methodName'));
62 $params=$methodCall->appendChild($xml->createElement('params'));
63 $param[1]=$params->appendChild($xml->createElement('param'));
64 $value[1]=$param[1]->appendChild($xml->createElement('value'));
65 $param[2]=$params->appendChild($xml->createElement('param'));
66 $value[2]=$param[2]->appendChild($xml->createElement('value'));
67
68 // Set the node values
69 $methodName->nodeValue="weblogUpdates.ping";
70 $value[1]->nodeValue=$blogTitle;
71 $value[2]->nodeValue=$blogUrl;
72
73 $xmlrpcReq = $xml->saveXML(); // Write the document into a string
74 $xmlrpcLength = strlen( $xmlrpcReq ); // Get the string length.
75
76 echo "Here's the xml-message I generated (size: $xmlrpcLength bytes):";
77
78 echo "\n<pre>\n";
79 echo htmlentities($xmlrpcReq);
80 echo "</pre>";
81
82 echo "<dl>";
83
84 // Proceed every link read from file
85 foreach ( $myList as $host => $path)
86 {
87 if($showDebugInfo) echo "<hr/>";
88
89 echo "<dt><strong>Pinging host: $host </strong>";
90 $httpReq = "POST /" . $path . " HTTP/1.0\r\n";
91 $httpReq .= "User-Agent: " . $userAgent. "\r\n";
92 $httpReq .= "Host: " . $host . "\r\n";
93 $httpReq .= "Content-Type: text/xml\r\n";
94 $httpReq .= "Content-length: $xmlrpcLength\r\n\r\n";
95 $httpReq .= "$xmlrpcReq\r\n";
96 echo "</dt>";
97
98 if($showDebugInfo)
99 {
100 echo "<dd><strong>Request:</strong><pre><span style=\"color: #cc9900\">".htmlentities($httpReq)."</span></pre>";
101 echo "<strong>Answer</strong>:<span style=\"color: #99cc00\"><pre>";
102 }
103
104 // Actually, send ping
105 if ( $pinghandle = @fsockopen( $host, 80 ) )
106 {
107 @fputs( $pinghandle, $httpReq );
108 while ( ! feof( $pinghandle ) )
109 {
110 $pingresponse = @fgets( $pinghandle, 128 );
111 if($showDebugInfo) echo htmlentities($pingresponse);
112 }
113 @fclose( $pinghandle );
114 }
115 if($showDebugInfo) echo "</span></pre></dd>";
116 }
117 echo "</dl>";
118 echo "<p>FINISHED</p>";
119
120 ?>
121
Here's an example input-file (pinglist.txt):
1
2 http://blogsearch.google.com/ping/RPC2
3 http://rpc.technorati.com/rpc/ping
4 http://www.newsisfree.com/xmlrpctest.php
5 http://ping.bitacoras.com
6 http://ping.blo.gs/
7 http://ping.bloggers.jp/rpc/
8 http://api.moreover.com/ping
9 http://api.my.yahoo.com/RPC2
10 http://api.my.yahoo.com/rss/ping
11 http://www.bitacoles.net/ping.php
12 http://bitacoras.net/ping
13 http://blogdb.jp/xmlrpc
14 http://www.blogdigger.com/RPC2
15 http://www.blogoole.com/ping/
16 http://www.blogoon.net/ping/