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 ?
Asked
Active
Viewed 780 times
1
-
You should put php file in cron as it will have logic. HTML file is just the output. – Disha V. Aug 01 '15 at 09:53
-
cron job depends on server you are using. this is for linux - http://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job – Harish Lalwani Aug 01 '15 at 09:54
2 Answers
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.
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.

Artem Baranovskii
- 983
- 5
- 13