If and when you need to run a certain php script as a kind of daemon program, you can use the popular supervisord software package for this purpose.
Very often this will work much better, more efficiently and more conveniently as a replacement for clumsy php scripts in the system cron. Run the application in a short cycle, set the counter of time and repetitions – you’re done!
Create a file at /etc/supervisor/conf.d/myprogram.conf and enter the file contents:
1 2 3 4 5 6 7 | [program:myprogram] command=php /home/USERNAME/program.php autostart=true autorestart=true user=USERNAME redirect_stderr=true stdout_logfile=/home/USERNAME/logs/program.log |
Then restart supervisor with service supervisor restart and your program should launch.