Alexa 500 server stats (the code)

April 29th, 2005. Tagged: News/personal

The Alexa stats are described in this posting here. I just wanted to share the code if anyone's interested.

< ?php ini_set("max_execution_time", 2400); // 40 minutes of execution time require_once 'config.php'; // just has the path to PEAR require_once 'PEAR.php'; require_once 'DB.php'; require_once 'HTTP/Request.php'; $request = &new HTTP_Request('', array('allowRedirects' => true, 'timeout' => 10));
// this is not really necessary
$request->addHeader('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.7) Gecko/20050414 Firefox/0.9.1');

// db object
$db = DB::connect('mysql://root@localhost/alex',true);

// get all sites
$sql = 'SELECT url FROM sites';
$sites = $db->getCol($sql);

foreach ($sites AS $url) {

echo "\n" . '
URL: ' . $url;
echo ', url set, sending request ...' . "\n";
flush(); // this is supposed to force sending something to the browser
echo ', request send...' . "\n";
echo $server = $request->getResponseHeader('Server');
echo "\n";

if (empty($server)) {
$server = 'na'; // no Server header or no response

// update the table with the result
$sql = 'UPDATE sites SET server="' . addslashes($server) . '"' .
' WHERE url="'. $url .'"';



Here's an SQL dump that contains the `sites` table definition and the data. The data contains all the 499 top Alexa URLs plus the results from the server test.

Tell your friends about this post on Facebook and Twitter

Sorry, comments disabled and hidden due to excessive spam.

Meanwhile, hit me up on twitter @stoyanstefanov