1

On the code above im able to have an interval until 60 Hours if the script is loaded every minute. In other words, the script above will be loaded by a cronjob every minute.

Since the users that will use this may use hosting that do not have rights to set Cronjobs, I need to make this script only with PHP.

How can I do it to make it for longer, for exemple for once a month (672 hours)?

/** suppose we have 1 hour and 1 minute inteval 01:01 */

    $interval_source = "01:01";
    $time_now = strtotime( "now" ) / 60;
    $interval = substr($interval_source,0,2) * 60 + substr($interval_source,3,2);


    if( $time_now % $interval == 0){
    /** Run things after interval */
    }

donatelo
  • 11
  • 5
  • 5
    We use either cronjobs (linux) or scheduled tasks (windows) for it. No need to keep the script running. – DigiLive Feb 09 '18 at 15:27
  • 1
    use the crontab. – delboy1978uk Feb 09 '18 at 15:28
  • See how to use crontab with script https://stackoverflow.com/questions/22358382/execute-php-script-in-cron-job – Fky Feb 09 '18 at 15:32
  • Possible duplicate of [Execute PHP script in cron job](https://stackoverflow.com/questions/22358382/execute-php-script-in-cron-job) – Fky Feb 09 '18 at 15:33
  • Thanks you all for the Reply. The problem is that I can not use Cronjobs for this because the se users that will use my script may have no previleges on the hosting for that or could use windows as Server. – donatelo Feb 09 '18 at 19:16

1 Answers1

0

If you get a reasonable amount of daily visitors you could also let a hit activate a certain script once a month for example: (I use this method to record some info about my site daily at 23h30)

Jere_JBC
  • 31
  • 2