Google Last Cached Date Finder In PHP

4th September 2009 - 4 minutes read time

When Google looks at a page it takes a snapshot of that page and uses this to match against the query a user entered. To view these cached pages run a Google search and look at the Cached link next to the green URL text of the result. When you view the cached page Google will also give you a date that the page was last cached on. This can be used as a metric of your sites importance as the more often the site is cached, the more favourable Google views your page.

Taking a reading of this metric can therefore be useful, which is why I set about to create a class to retrieve this result.

Download the Google Cache class here.

The class works by constructing a query string with a given URL, which it then uses to download the cached page from Google. It then detects if a date string has been found and if so returns this. If anything went wrong along the way then the function will return false. In an effort to stop Google getting angry with you for trying to spam their site with multiple requests the class will also randomly select from a series of addresses. There is only one address (a single IP address) at the moment, but to add more simply add them to the $googleAddresses array at the top of the class. Every time the getLastCached() function is run a new address will be randomly selected. If you enter an address that causes an error then the function will return false.

Use the class in the following way:

$googleCache = new GoogleCache();
$date = $googleCache->getLastCached("");

This will return the date when the BBC home page was last cached, which should be very recent.


your nice script has worked for me for a few months but now it has stopped working without changing anything. I've looked into the codes but couldn't find how to resolve this problem. Would you please help. Many thanks,

David (Sun, 06/06/2010 - 06:19)

It's probably because Google have changed something that this class is looking at. I'll take a look and see what I can do :)

Change the following line:

protected $googleAddresses = array("");


protected $googleAddresses = array("");

KDS (Tue, 07/19/2011 - 11:20)



Your script worked great for me but now it stopped working... something wrong?

Kind Regards,


Peter (Mon, 08/22/2011 - 02:40)


As another commenter posted above (thanks KDS) if you change the IP address used in the property $googleAddresses to be then it seems to work nicely.

I have updated the class to incorporate this change so you can download it again if you wish :)


it's really very help ful and working nice.

Now can you give some idea to get result for multiple urls at one time.


wasim (Mon, 11/14/2011 - 07:50)


Hello All,

Does anybody know a good position checker php script? This will save me a lot of time every morning...

Thanks in advance!

Kind Regards,


Genesys (Mon, 12/12/2011 - 22:55)


It's tricky. They have no API for this and it's against their terms and conditions so they will make it deliberately difficult for you to scrape their site for content.

That said, it is possible. I've done it in the past and have done all sorts of things to get around the checks that Google does to stop you.


I tried it in my localhost and run it for multiple urls.

It's working proper but when I upload it in my server it's show me an the default date of the server.

It's not giving me proper output please anyone help me to solve this out.

wasim (Sat, 12/24/2011 - 06:18)


Hey I also face the same problem.

I had made it for multiple site and it's working perfect and show proper output but when I upload it at live server

it show me blanke value.

It show me nothing so if you find anything so please inform me.

sharik (Sun, 12/25/2011 - 04:19)

Add new comment

The content of this field is kept private and will not be shown publicly.