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 ?
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.