1

I have my HTML page with a few PHP scripts inside, I would like one of those scripts to repeat every minute. I created a new "minute.php" file and I would like to make it call the script every minute. I don't get in which file I have to put the script that I want to run every second, in the original HTML page or in the "minute.php" file. Where do I put the * * * * * ... line ?

baao
  • 71,625
  • 17
  • 143
  • 203
LeoQLF
  • 63
  • 1
  • 2
  • 6

2 Answers2

2

If you are expecting the change in HTML after each minute use setInterval and not Cron Job.

Call jQuery Ajax Request Each X Minutes

You can use the built-in javascript setInterval.

var ajax_call = function() {
  //your jQuery ajax code
};

var interval = 1000 * 60 * X; // where X is your every X minutes

setInterval(ajax_call, interval);

or if you are the more terse type ...

setInterval(function() {
  //your jQuery ajax code
}, 1000 * 60 * X); // where X is your every X minutes

ajax_call above can be ajax call to minute.php.

Community
  • 1
  • 1
Jigar
  • 3,256
  • 1
  • 30
  • 51
0

You could reside your minute.php script in any place you desire. Like /var/www/site/cron/minute.php for example.

To execute this script you may execute binary php program and pass it the path to the script as argument like the following:

$ /path/to/php /var/www/site/cron/minute.php

To run this command every minute you have to add the following record in crontab:

* * * * * /path/to/php /var/www/site/cron/minute.php

Note that the path to the script should be absolute.