PHP Classes


Recommend this page to a friend!
  Classes of Peter Kahl   PHP Alexa Rank Top Domain   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Alexa Rank Top Domain
Retrieve domains from Alexa top 1 million domains
Author: By
Last change:
Date: 5 years ago
Size: 1,301 bytes


Class file image Download

Top Domain

Top 1 million domains list. Random domain. Check if your domain is in the top 1 million. Get a list of X domains.

This library utilizes Alexa's Top 1 Million Domains data file:


use peterkahl\TopDomain\TopDomain;

$tdomObj = new TopDomain;
$tdomObj->CacheDir = '/srv/cache';

# Get random domain
$temp = $tdomObj->RandomDomain();
echo $temp['domain'] .' ............. '. $temp['rank'] ."\n";

# Check if given domain is in the top 1 million.
$temp = $tdomObj->FindDomain('');

echo $temp['domain'];
if (empty($temp)) {
  echo ' is not in the top 1 million.' ."\n";
else {
  echo ' is in the top 1 million with rank '. $temp['rank'] .'.' ."\n";

# Get a list of domains 1 through 100.
$temp = $tdomObj->GetDomains(1, 100);

foreach ($temp as $val) {
  echo $val['rank'] .' ............. '. $val['domain']  ."\n";


You probably want to set up a crontab job to periodically update the Alexa data file, perhaps by using the shell script Don't forget to edit this file with the correct location of your cache directory!