skip to Main Content

This question may seem repetitive, as there are many threads around with the same subject, but thing is that most solutions seems to be linked with terminal coding, which i’m not comfortable with. The problem is simple i have a php script that needs to be executed very 10 seconds. Cron job in cpanel allows only upto 1 minute. What’s the workaround to let cron work every 10 seconds ?

4

Answers


  1. You can use simple bash-script like

    #!/bin/sh
    while [ true ]
    do
    php script.php
    sleep 10
    done

    Login or Signup to reply.
  2. CRON jobs are the standard way to run some tasks periodically. Setting cron jobs require access to the terminal. However, some shared hosting providers don’t provide this and you need to set it up through their interface.

    If you hosting don’t provide this you can third-party services that will call you url every ‘X’ seconds.

    Here are few of them:

    You can Google for more

    Note: You can have publically expose the PHP file as an url

    Login or Signup to reply.
  3. You can use the GUI Cpanel, select “once per minute” an try with something like the next command:

    /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php
    
    Login or Signup to reply.
  4. Let the cron job run after every minute and in your php script the following code example might help you out. I have used counter limit to 6 because this script will run after every ten seconds and six times in one minute.

    <?php
    for($i=0;$i<6;$i++){
        sleep(10);
        task();
    }
    
    function task(){
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search