MVC And Cron/Scheduled Jobs/Tasks

What’s the best way to have an MVC deal with cron jobs? Is it best for the cron job script(s) to make their own connection to the database and be more procedural then OOP?

I don’t know what the industry standard is but I don’t see why cron jobs would need to be handled any different than regular web pages. The easiest way is to get the cron to request a specific URL with wget and then the script works in the same way as requested with a browser and has the same $_SERVER environment.

Alternatively, if I want the cron to invoke the script via command line then I add a very small proxy file, like cron.php, and this file sets up the initial input parameters and runs the same framework from there. So in either case I keep cron actions within the same framework, no need to have a separate code base for them. Separate connection to the database - certainly, just like any other web page (unless you use persistent connections, which is tricky in its own way).

Possibly in conjunction with using htaccess so that only the server’s IP can hit the url and admins being able to run the cron jobs via a page where they have to be logged in and have the rights to hit the cron script

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.