Results 1 to 3 of 3

Thread: Multiple Pinging With Time Limit

  1. #1
    Join Date
    Feb 2010
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Multiple Pinging With Time Limit

    Hello guys,
    Can somebody show me how to modify this script?
    I wish to execute it WITHOUT cron job, but I wish to limit that it can not be executed more than once a day (for instance after 86400 seconds or more) when first time is required in index.php.
    Can somebody help me with this?
    Thank you

    Code:
    <?php
       // Please, edit these variables to your needs
    
       $blogTitle="Title Of your blog";
       $blogUrl="http://www.yourblog.url/";
       $pingListFile="pinglist.txt";
       $showDebugInfo=FALSE; // Do you want verbose output?
    
       // Stop editing here
    
       // PingRPC.php
       //
       // 2007 by Sascha Tayefeh
       // http://www.tayefeh.de
       //
       // This is a PHP5-based XML-RPC ping script. It reads a one-column
       // fully qualified URL-list from a file ($pingListFile). Here is
       // an example how this file must look like:
       // ----------------------
       // http://rpc.icerocket.com:10080/
       // http://rpc.pingomatic.com/
       // http://rpc.technorati.com/rpc/ping
       // http://rpc.weblogs.com/RPC2
       // ----------------------
    
       $replacementCount=0; 
       $userAgent="pingrpc.php by tayefeh";
    
       // Read pinglist file. Must contain one fully qualified URL
       // (e.g: http://rpc.technorati.com/rpc/ping) PER LINE (-> 
       // 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 "<h1>Ping process started</h1>";
    
       echo "<p>Reading URLs from file $pingListFile: ";
       echo count($myList)." urls read.</p>";
    
       // 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&apos;s the xml-message I generated (size: $xmlrpcLength bytes):";
    
       echo "\n<pre>\n";
       echo htmlentities($xmlrpcReq);
       echo "</pre>";
    
       echo "<dl>";
    
       // Proceed every link read from file
       foreach ( $myList as $host => $path)
       {
          if($showDebugInfo) echo "<hr/>";
    
          echo "<dt><strong>Pinging host: $host  </strong>";
          $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 "</dt>";
    
          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 );
    	    if($showDebugInfo) echo htmlentities($pingresponse);
    	 }
    	 @fclose( $pinghandle );
          }
          if($showDebugInfo) echo "</span></pre></dd>";
       }
       echo "</dl>";
       echo "<p>FINISHED</p>";
    
    ?>

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You must store the last time it was used.
    If you have a database, that may be best or you can use a .txt file on the server to remember it also.

    This has nothing to do with the script, and it can work like this:

    PHP Code:
    $t getmytime(); //get the stored time, this is just an example/placeholder
    if (time()-$t>=(24*60*60)) { //execute only if it's been longer than 24 hours
    savemytime(time()); //store the current time-- to a file, or to a database, this is just an example/placeholder
    ///place all the other code here
    //....

    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2010
    Posts
    25
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    I’m new with PHP, and now I try to figure out how to do next thing.
    I think that is best solution might be, if rss.xml file (file where is RSS feed stored) will be check out and if it is changed in last 24 hours, than to run script, else if rss.xml is unchanged to do nothing.
    Does anybody think that there is better solution?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •