Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we configure cron job's time interval through PHP script?

Tags:

php

cron

Can we configure cron job's time interval through PHP script, so that the time interval should not be set manually, but through a PHP script, whether it takes time interval from Database or fixed (but from within the PHP code).
Thanks in advance

like image 936
swdeveloper Avatar asked Aug 08 '11 11:08

swdeveloper


People also ask

Do you know how do you setup cron jobs for PHP website?

Timing – set the weekday, months, days, hours and minutes. Execute – the cron job needs to be called in PHP to run – that's located at /usr/bin/php path. Script Path – the path of the file you want to run. Output – you are allowed to add the cron output to a file or discard it. /dev/null 2>&1 will discard.

How do I run a cron job at a specific time?

Every minute: if you want to run a cronjob every minute then you would use the wild card symbol * . If however you wanted to run it every x minutes you would use */x for example every 5 minutes would be */5 or for every 15 minutes */15 . The next option is to specify the minutes separated by , for example 3,16,23,48 .


1 Answers

I think it is much better to let your application control the frequency of events instead of the cronjob. Let the cronjob run a certain action of your application every minute. The action then for example checks a database table named cronjobs and runs the jobs marked for running by either a frequency number or a timestamp.

If you do it like this, you can add new jobs programmatically from everywhere, e.g. via an cronjob interface. The solution is easier to maintain, to test and to document.

like image 63
markus Avatar answered Sep 21 '22 02:09

markus