Forum Moderators: coopster

Message Too Old, No Replies

MySQL Query On Page Update?

         

McBlack

10:51 pm on Feb 12, 2008 (gmt 0)

10+ Year Member



I'm trying to make an auto-bot that performs a MySQL query. I want it only to do this when the page updates. I'm using filegetcontents to get my information. How can I make it perform this query when the requested page is updated?

thanks....

whoisgregg

11:28 pm on Feb 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, you'd have to store what the page was the last time you checked it, then compare that to the current check. If those don't match up, then the page has changed and you perform the query.

Of course, there's lots of things people can do that will change their page content without the main content of the page changing (think "quote of the day" or navigation changes). So, a really robust page update checker can't just rely on simply comparing the strings, but it may work for your purposes.

So, very roughly, your script might look something like:

$cache_path = '/path/to/some/directory/php/can/write/to/';
$url_to_check = 'http://www.example.com/page1.html';
if(file_exists($cache_path.md5($url_to_check))){
$last_content = file_get_contents($cache_path.md5($url_to_check));
$current_content = file_get_contents($url_to_check);
if($last_content != $current_content){
// perform a mysql query
}
}
file_put_contents($current_content, $cache_path.md5($url_to_check));