We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cronjob in a web application

I have to create some cronjobs for mailing and other purpose in my web application then, how can I do this? I mean I have to made another bootstrap.php for cronjob into tha same application or have to create different application for cronjobs.



43.9k

Hi,

Maybe this post may help you.

Related scripts.

I know linux and crontab as we used many times in other projects but in phalcon I have a question that is cli.php bootstrap is necessary to run the cronjob or i can run any controller method at crontab by specifying proper related url.



43.9k

Do you mean accessing via a cron job to https://mysite/controller/action with curl ?

This is the file called by cron task in the example given by Thien in the forum post. It is a regular php file. You can execute it from the command line.

Do I need this https://github.com/SidRoberts/phalcon-cron or i can configured any controller method in timely interval.



43.9k

You do not need (imho) any third party library.

  • for accessing https://mysite/MyController/MyAction use curl in cron job
  • to interact within the console (pass parameters, but this seems to be useless in a cron job), use a dedidicated command line app
  • otherwise use the solution that this forum app use (see links above). In cli.bootstrap.php I would load a dedicated cli-services.php (without view, flash, dispatcher, sessions )

In all my apps, I don't duplicate Controller functionality. I make Tasks that do their own thing. If there is functionality in a Controller that you need to use elsewhere, consider if that functionality would fit in the Model. If not, break it out into a Component that both your Task and Controller can use.

You don't necessarily have to use a separate bootstrap file, but sometimes you might need to due to the different operating environment.