How can I run a php file or execute a mySQL query automatically depending on the time? For example, by 12mn I want my server to automatically run somefile.php.
More: I have a LAMP setup.
You are looking for the Cron jobs. you can schedule the PHP file to be executed with the cron and cron will take care of rest.
If you are on LAMP platform, check out how to setup cron.
You can do this by using Cron :
https://help.ubuntu.com/community/CronHowto
ex :
* */12 * * * php /cron/script.php
.txtfile that store last execution time, but is need too many visits, or a "infinite while" (server need support)