Hi,
Crontabbing is the solution I use. While your script is cleaning out the database, it could also dump it using mysqldump, gzip it and send it away so you have an off-site backup.
PHP as a shell-scripting language was described in www.phpbuilder.com/columns/darrell20000319.php3
Johan