I want to create a directory and fetch alexa rank as a field for a list of urls.
I have created a function that takes as a variable the url and returns its rank.
The problem is that the page is very very slow and crashes. (not working for about 50 urls in the same page :))
I know that function works properly and i assume that i have to put the function as a preprocess one in a template file or sth like that but i dont know exactly the steps.
I would appreciate if anyone could help.
What i tried to do is:
1)
function alexaRank($domain)
{
$remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);
$search_for = '<POPULARITY URL';
if ($handle = @fopen($remote_url, "r")) {
while (!feof(!$handle)) {
$part .= fread($handle, 100);
$pos = strpos($part, $search_for);
if ($pos === false)
continue;
else
break;
}
$part .= fread($handle, 100);
fclose($handle);
}
$str = explode($search_for, $part);
$str = array_shift(explode('"/>', $str[1]));
$str = explode('TEXT="', $str);
return $str[1];
}
I put this function in Global php field (using Vies php module) in Setup mode (ticked "Use setup code")
2)
"Output code"
$tmp= $row->field_url_dir_item; //This should return the url but it actually returns node ID
$node = node_load($tmp); // So i load node
$tmp = $node->field_url_dir_item['el'][0]['url']; // Get the url
print alexaRank($tmp); //Fetch alexa