I have a Cpanel web host without terminal and now I have PHP code that I want to run forever without any stops.
This code sends some requests and checks the response and then saves something in the database. I have written this code completely.
Please tell me a simple way to run this code non-stop or every second.
As i know, Cronjob for at least every minute. not for every seconds(or run forever).
I want a simple way to run a PHP code permanently on the server and not slow down the server.
3
Answers
you have to use
Cron jobs
, please refer to this links for more information,https://www.tutorialspoint.com/cpanel/cpanel_cron_jobs.htm
https://docs.cpanel.net/cpanel/advanced/cron-jobs/
You can define 60 cronjobs to run every minutes. First one runs immediately, but second one sleep for a second, than run, 3rd one sleeps for two seconds etc.
Example Cron Command:
Alternatively you can use GNU package mcron or SystemD timer unit.
An extremely simple way to achieve this is to have a forever loop, like this: