Getting Google’s last visit date from the Google API

When Vanessa Fox over at the Webmaster Central Blog said they would update the “retrieved on” date even when a page hadn’t changed, it suddenly became very cool info. This means you can see when a URL was last spidered, even if you don’t have a Sitemaps account for the domain. This triggered me to find a way get that date through the Google API, and do nice stuff with it. It worked, and this is how i did it.

First, we have to get the cached page from the Google cache through the API:

function GoogleCache($url) {
$soapclient = new soapclient('');
$soapoptions = 'urn:GoogleSearch';
$params = array(
'url' => $url
$ret = $soapclient->call('doGetCachedPage', $params, $soapoptions);
$err = $soapclient->getError();
return $ret;

Now we have to make a function which uses this one, and gets the last visit date out of it:

function GoogleLastSpidered($url) {
$cache = GoogleCache($url);
preg_match("/.*as retrieved on (.*).
return $matches[1];

If you want, you could now feed the output of this function to strtotime() to do stuff with the date, or you could just echo it.

[tags]seo, google api, google cache[/tags]

Tags: , runs on the Genesis Framework

Genesis theme frameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Whether you're a novice or advanced developer, Genesis provides you with the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Read our Genesis review or get Genesis now!