In order to have your program run automatically, you need to write your php script as a shell script. However php needs to be compiled as a CGI binary instead of an Apache module to do so (this may be different for newer versions but I'll leave you to do that research). Shell script example:
#!/usr/local/bin/php -q
<?php
print("Hello, world!\n");
?>
the -q switch suppresses html headers.
Now just learn cron and you're set ;-)