skip to Main Content

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


  1. 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/

    Login or Signup to reply.
  2. 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:

            • sleep 1 && {your cron command to run your script} 2>&1

    Alternatively you can use GNU package mcron or SystemD timer unit.

    Login or Signup to reply.
  3. An extremely simple way to achieve this is to have a forever loop, like this:

    <?php
    
    while (true) { //true will always be true
        //put here the code you want to be repeated forever
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search