1

I want to run php script at the particular time and then update the time to next interval. Is it possible to set cron job time duration from php script ?

For Example: 1 - set cron to run at the next sunday, 2 - then update the cron time to another particular time from php, 3 - so on..

1 Answer 1

1

You can set your cron job to run at a constant interval (every minute, every hour, etc.), and within the job, check if the action needs to be performed. Laravel framework, for example, does this with their scheduler. There is a single entry into the crontab, and within the job itself, it determines what it actually needs to run.

To keep track of the job internally, you can use a database to store the next run time. If the current time is greater than the next run time, you perform the action and update the database based on your rules for determining the next interval.

Sign up to request clarification or add additional context in comments.

6 Comments

Is there any other way? Cause i dont want to run cron job at every minute unnecessarily.
If the all the script does is CHECK if it needs to do the action, it will be really lightweight and will have very little performance load. Also, if you are ok with it checking only once an hour, or once a day, that is fine too.
I want to send at any particular minute. so I am checking any other way to do it properly.
This is the way to do it properly.
Hi Jeremy, I am aware of this method. I want other way than running my cron at every minute. Any other way if i can schedule cron job to run of particular time only, and then update the scheduled time on any other time. Thanks..
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.