Sergio Varela Sergio Varela - 5 years ago 242
PHP Question

how to run from codeigniter a cron job whose parameters are dynamic

I need to run a codeigniter job once everyday, I need to check my mysql db in order to see if there is an scheduled email task for that day, if there is one, send the emails for that service; previously, that service was made manually, there, what we used to do was to create an uri with the proper parameters and submit it via a browser, like this:

http://www.ourdomain.edu/ci/controller/method/1/49/7


where the 1, the 49 and the 7 are dynamic parameters, the 1 is a status parameter that might change, the 49 is the id that belongs to that service and only to it (no other service has that id, and it changes from an email service to the next) and the 7 indicates the size of the batch to send (per email account serving the emails), what I can do now is to echo the uri for command line use for each case:

controller method 1 dynamic_id_to_use 7


so, it would be easy to create the full command for console use like this:

$: php index.php controller method 1 dynamic_id_to_use 7


but this is not what I need to do, what I need to do is to execute a cron job that checks for scheduled job for that day, read its parameters and process them (I can do that right now), if there is at least one, run a script or codeigniter job that executes the line command
php index.php controller method 1 dynamic_id_to_use 7
, The services can be scheduled by the users whenever they need it to, so, that´s why consecutive services and their id´s are not necessarily consecutive, thank you in advance for your assistance.

Answer Source

Let's do one thing make a new table with 5 columns

Cron_table
-----------
Id
status
Dynamic Id
Batch size
Cron-status

Now store all your cron details to this table as per your requirements and set cront-status to zero. Now make a cron for this to take data with cron-status =0 and after getting results process the work you want to after work done set cron-status = 1.

Let me know if this helps you or not.

Enjoy coding ...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download