The Developer Day | Staying Curious

Sep/08

12

PHP Google Page Rank Class Working on Linux

If you found this blog post on while searching for a php google page rank class implementation that works on non windows machines then it is your lucky day! You found it! Congratulations!

To my knowledge this is the first available php google page rank retrieval implementation that works on any platform. We have spent hours searching for such a thing online but we couldn’t find it. There are some php google pagerank tools online, they all work, but they are all limited to windows machines.

Why is so you might ask? Well originally the google pagerank retrieval algorigthm is not public. But google made a browser plugin that was able to calculate the google pagerank for any website you visit. So some freaky geeks dissasembled that plugin and got their hands on the google page rank calculation implementation.  Then this implementation was ported to various languages such as Javascript, PHP. The google page rank implementation is sort of protected by calculating a “unique” hash of the given URL. And here the MAGIC begins.

To calculate this hash the algorithm overflows 32bit integers on XOR operations. Aaaand.. 32bit XOR overflows work quite differently on windows and linux in PHP! If you overflow a 32bit integer on windows it just truncates the result to 32 left most bits and returns a new integer. SMART! And on linux XOR overflow just returns the MAX INTEGER value. What did we do? Oh.. We created a simple class to simulate windows 32bit XOR operations overflow using the PHP gmp extension. Tadam! We have also cleaned up the code, documented and made it look shiny ;)

You can download  and use it at your own will. I hope this will help you. If it did just leave a comment and say thanks because we are such nice guys to help you out ;)

To use the class try:

require_once("GooglePageRank.php");
echo GooglePageRank::get("http://www.yahoo.com");

Happy Programmers Day!

p.s  Google™ search engine and PageRank™ algorithm are the trademarks of Google Inc.

Update: PageRank class relies on the GMP extension which is not always enabled by default. On Linux Ubuntu it comes as a separate package php5-gmp.

RSS Feed

5 Comments for PHP Google Page Rank Class Working on Linux

InformaticaAutonomos | February 11, 2010 at 4:54 PM

This class don’t reslove all pageranks.
Example: maps.google.es

Author comment by Žilvinas Šaltys | February 12, 2010 at 11:51 AM

Hi,

Thanks for reporting this. There was an issue with URL validation. would have worked. I’ve fixed the issue and it should now work bothways.

Thanks.

Paweł P. | April 6, 2010 at 8:05 AM

“Fatal error: Call to undefined function gmp_init()” Ahhh …

x | August 19, 2010 at 1:05 PM

not working for me ;/

Author comment by Žilvinas Šaltys | August 20, 2010 at 8:34 AM

Can you tell me what URL you’re trying?

Leave a comment!

<<

>>

Find it!

Theme Design by devolux.org