[Php] Auto Pinger Code

meannn

Elite Member
Joined
Apr 22, 2009
Messages
1,908
Reaction score
2,771
This is a script that pings your url to ping sites from a file.

When you manually/auto post something to your site, add this code
and this script will automatically pings your post. This function is already on wordpress, however, this is for those who don't use Wordpress.

PHP:
<?php  

//********************************************************
  
$blogTitle="Page title";    
$blogUrl="http://www.yoursite.com/page";    
$pingListFile="pinglist.txt";    
$showDebugInfo=FALSE;     
$replacementCount=0;     
$userAgent="pingrpc.php by meannn";  

//********************************************************

   $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;
   }


   $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.


   foreach ( $myList as $host => $path)
   {
      if($showDebugInfo) echo "";

      echo "";

      if($showDebugInfo)
      {
echo "";
      }

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

pingslist.txt

Code:
http://pastie.org/1948534
 
Last edited:
Awesome Share!

I was going to do something like this but I see you've beat me to it lol.

Thanks :)
 
Sorry for resurrecting this thread, but you have an error in your code. It should read:

<?php //********************************************************

$blogTitle="Page title";
$blogUrl="http://www.yoursite.com/page";
$pingListFile="pinglist.txt";
$showDebugInfo=FALSE;
$replacementCount=0;
$userAgent="pingrpc.php by meannn";




//*Edited by joaquin112






$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;
}


// 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.




// Proceed every link read from file
foreach ( $myList as $host => $path)
{
if($showDebugInfo) echo "<hr/>";


$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";


if($showDebugInfo)
{
echo "<dd><strong>Request:</strong><pre><span style=\"color: #cc9900\">".htmlentities($httpReq)."</span></pre>";
echo "<strong>Answer</strong>:<span style=\"color: #99cc00\"><pre>";
}


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

echo $pingresponse;

if($showDebugInfo) echo htmlentities($pingresponse);
}
@fclose( $pinghandle );
}
if($showDebugInfo) echo "</span></pre></dd>";
}



?>
 
Back
Top