"Fossies" - the Fresh Open Source Software Archive

Member "libs/PHPCrawler/PHPCrawlerDNSCache.class.php" (8 Jan 2013, 1434 Bytes) of package /linux/www/SitemapCreator.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 /**
    3  * Simple DNS-cache used by phpcrawl.
    4  *
    5  * @package phpcrawl
    6  * @internal
    7  */
    8 class PHPCrawlerDNSCache
    9 {
   10   /**
   11    * Array for caching IPs of the requested hostnames
   12    *
   13    * @var array Associative array, keys = hostnames, values = IPs.
   14    */
   15   protected $host_ip_array;
   16   
   17   public function __construct()
   18   {
   19   }
   20   
   21   /**
   22    * Returns the IP for the given hostname.
   23    *
   24    * @return string The IP-address.
   25    */
   26   public function getIP($hostname)
   27   {
   28     // If host already was queried
   29     if (isset($this->host_ip_array[$hostname]))
   30     {
   31       return $this->host_ip_array[$hostname];
   32     }
   33     
   34     // Else do DNS-query
   35     else
   36     {
   37       $ip = gethostbyname($hostname);
   38       $this->host_ip_array[$hostname] = $ip;
   39       return $ip;
   40     }
   41   }
   42   
   43   /**
   44    * Checks whether a hostname is already cached.
   45    *
   46    * @param string $hostname The hostname
   47    * @return bool
   48    */
   49   public function hostInCache($hostname)
   50   {
   51     if (isset($this->host_ip_array[$hostname])) return true;
   52     else return false;
   53   }
   54   
   55   /**
   56    * Checks whether the hostname of the given URL is already cached
   57    *
   58    * @param PHPCrawlerURLDescriptor $URL The URL
   59    * @return bool
   60    */
   61   public function urlHostInCache(PHPCrawlerURLDescriptor $URL)
   62   {
   63     $url_parts = PHPCrawlerUtils::splitURL($URL->url_rebuild);
   64     return $this->hostInCache($url_parts["host"]);
   65   }
   66 }
   67 ?>