Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Call a action every Monday

Hi,

How can I do to call an action from my Controller every Monday with Phalcon ?

There is a solution to do that ?

John.

Hey, if i understnad you correctly you can create a cronjob script which executes a curl to your action.

Info on curl: http://php.net/manual/en/function.curl-exec.php



12.6k
edited Nov '15

Perfect ! Thanks I'll try that :)

Edit : I can't accept your answer :O I don't know why.



44.8k
edited Nov '15

I think that you should be using a Task for this that basially instantiates a class that does the work. In my project I broke out services that would only be relevant on the web (ie controllers) and then services that are relevant on the CLI and web.

See:

edited Dec '15

You cannot do it without something calling your action via url. And that's what is cron job made for. You put a cron job (crontab), and make it execute your action via curl every monday.

Note: you need Linux for this, either on your server or elsewhere as long as external system can access your URL. P.S. and there is another solution, basically to have your PHP CLI program daemonized, so it will run in an endless loop and do the cron tasks for you.



44.8k
edited Dec '15

You cannot do it without something calling your action via url. And that's what is cron job made for.

Cron will execute a command and that command could be have curl access a URL or an entry into a Phalcon Task. In my project that would be done with with a call to /opt/webird/dev/webird.php do-stuff. They are both just commands, do you see?

I think that its better to set up these administrative tasks using a CLI because then they are not exposed to the world through the web server. Ahh, but then you could use your web server to restrict the IPs that can access that administrative function but why wouldn't you just want to take it off of the market entirely by doing it on the CLI. My Webird system is setup to be able to create and delete users from the CLI and going through a Task. Its nice and that sort of thing sets you up for building another layer beneath it that controls many things and maybe sets up an environment. Otherwise you end up with users being hard coded into the database schema. Any serious system should have a CLI interface for important administrative functions.

[edit] I don't know how to escape the underlines in the link so I'll just but the Phalcon Task documentation link here: https://docs.phalconphp.com/en/latest/api/Phalcon%5CLI%5Task.html