#!/usr/bin/php -q $tablename) { mysql_query("OPTIMIZE TABLE $tablename") or die(mysql_error()); } } # need root access (or similar) to run this command mysql_query("FLUSH TABLES") or die(mysql_error()); ?>