That code looks alright for the most part. The only thing is that the OP said that after 20 minutes, the db is cleared. This sounds to me like a cron job rather than something that would rely on the clients. In this case it would be a good idea to have php store the timestamp of the last clearing in the db(in a table that isn't cleared, of course), then have that timestamp loaded into the JS so it can count down from the approximate time remaining. That's basically just changing
var timeleft = 20*60;
to
var timeleft = <?php print (($t = $lastclear + 1200 - time()) > 1200 ? 1200 : $t);?>;
where $lastclear is the time of the last clearing retrieved from the db.