PHP Script to get Alexa Rank

Alexa traffic rank is a value given to any website by alexa based on it’s traffic. A lower traffic rank means higher traffic volume to a website. Alexa is providing an paid API to access it database. But there is a way to do this for free. To get this data in XML format use following URL<>

To parse this XML file either you can use regular expression match or use inbuilt php5 function simplexml_load_file. here i am doing this with simplexml_load_file

PHP code to get Alexa Rank

$xml = simplexml_load_file(''.$url);
echo $web." has Alexa Rank ".$rank;

To get other info like alexa backlinks, website load time, dmoz listing etc, use similar method to parse XML

Eg: To get alexa backlink


Alexa Rank checker Demo

Published by Sunny

A Mechanical engineer by education and web developer by passion and profession. He lives in Lucknow, India. Currently earning his livings by hitting keyboad. ;)

Join the Conversation


  1. I’ve made a little script that lets you add the Alexa Rank to a Mysql database.

    The script is nothing big. I was wishing to share it in exchange of small donations. The reason I’m asking for donations is because I’m having a little trouble taking care of my household and I’m hoping to go 100% freelancing.

    Thank you for being understanding.

    Have a wonderful day.

  2. Great post, I made an imrpoved version of this and I like to share.

    private function getAlexaRank($domain_name = ‘’)
    $xml = simplexml_load_file(‘’ . $domain_name);

    $rank = isset($xml->SD[1]->POPULARITY) ? $xml->SD[1]->POPULARITY->attributes()->TEXT : 0;
    //$web = (string)$xml->SD[0]->attributes()->HOST;
    $reach = isset($xml->SD[1]->POPULARITY) ? $xml->SD[1]->REACH->attributes()->RANK : 0;
    $delta = isset($xml->SD[1]->POPULARITY) ? $xml->SD[1]->RANK->attributes()->DELTA : 0;

    return [‘rank’ => $rank, ‘reach’ => $reach, ‘delta’ => $delta];

    So just call it by var_dump($this->getAlexaRank(‘’));


Leave a comment

Your email address will not be published. Required fields are marked *