Google Pagerank in PHP

Mark Woodman has created a nifty class which lets you query Google pagerank info in PHP 5 and above. The complete classes are available here.

The minimum classes required are ‘cacher.class.php‘ and ‘google_pagerank.class.php‘.

Sample code is shown below.

require_once("popstats/google_pagerank.class.php");
 
$rankObject = new GooglePageRank("http://www.someDomain.com");
 
$pageRank = $rankObject->pagerank;
 
echo $pageRank;

The class also supports result caching on the local machine, so if a second query arrives within the cache time limit the result saved in the local file is returned rather then going out and querying Google.

The ‘GooglePageRank’ class accepts cache time as a second parameter. So if you want to cache the result for 6 hours you set the second parameter for 21600 seconds (6 * 60 * 60):

$rankObject = new GooglePageRank("http://www.someDomain.com", 21600);

The default is set to 24 hours, which is more then adequate for most purposes.

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

[…] http://www.codediesel.com/php/google-pagerank-in-php/ addthis_url = ‘http%3A%2F%2Fdavidwalsh.name%2Ffirefox-3-hacks-jquery-kwicks-shorthand-css-xmpphp-page-rank-php’; addthis_title = ‘Weekend+Links+-+Firefox+3+Hacks%2C+jQuery+Kwicks%2C+Shorthand+CSS%2C+XMPPHP%2C+Google+Page+Rank+PHP’; addthis_pub = ”; […]

[…] Google RageRank in PHP — I can’t think of anything I would use this for, but somebody somewhere is obsessing over their PR and needs this. […]

Leave a comment

(required)

(required)