0

Im new to this.I have a cron file called xml.php and i want to run this file at a particular interval.This interval is set by admin on admin panel page.This interval will be stored in the database and i want to fetch that data from db.According to that the xml.php should run.If anybody know how to do this please help.Thanks in advance

Rakesh Shetty
  • 4,228
  • 6
  • 35
  • 76

2 Answers2

0

What you will need to do is save it as you wish in DB... but there is no way to dynamically change a crontab... What you can do tho is at point of saving to DB you can use PHP to manipulate the crontab using the details that are saved/to be saved you can construct an appropriate crontab entry - see this for more details: Use PHP to create, edit and delete crontab jobs?

It will also depend on the hosting company on their permissions if they will let you execute shell commands from within PHP.

Community
  • 1
  • 1
Brian
  • 7,632
  • 2
  • 22
  • 32
0

Create a script that checks the DB for the last run of the file and the current time difference. If the interval is correct then run the xml script if not then exit. Use cron to run the new script every minute (so every minute it will check if the script needs to be run and run it only if it's time).

Odinn
  • 768
  • 4
  • 23
  • suppose if admin wants to run cron file after 15min or after 5min then what ? – Rakesh Shetty Jun 27 '12 at 08:46
  • The cron itself calls a script (lets say, run.php) that checks if the xml.php file needs to be run. all run.php does is check the last runtime of xml.php and the current time, calculates the difference and check if the difference is >= interval. if so it runs xml.php and updates last runtime in the DB otherwise it exits. You will need to add another field which keeps the last runtime in the DB. If the user changes the interval it should be OK. – Odinn Jun 27 '12 at 08:49
  • Thanks @Odinn..You save my ass – Rakesh Shetty Jun 27 '12 at 15:27