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.

Using controllers as task

Hello, I've got a webservice that runs as a module of my phalcon application. All the controller responses are in json and it doesn't use the view. I'd like to call the webservice through the command line but i can't make tasks working with controller actions withour rewriting al the task actions. I want to call an url like http://www.mysite.com/webservice/order/get/323 with:
$ php cli.php webservice order get 323
My cli support the modules. Any ideas?



1.8k

Maybe I've been not clear, sorry. I already have my cli environment. What I need is something like an adapter in order to use my web service controllers through command line without rewriting every single action in tasks (why doing the same thing two times) . the only idea I have is to call directly the web service by curl or wget... But it's very inelegant and slower.



66.6k

you can use exec/shallexec etc.., calluser_func somehow, no idea really



48.3k
Accepted
answer
edited Oct '17

Well, your API response is JSON, but via HTTP protocol. Thus, you need a way to send HTTP request and fetch response, i.e. trim out HTPP headers. Cli by default does not work with HTTP. So exactly CURL is the way to. You could also go with plain and simple file_get_contents of your endpoints, but I suggest (php) cURL for maximum control over your requests.

That would be microservice architecture, you're using standardized protocol (HTTP) to fetch remote results from another app (in this case your app), connecting two separate apps to work together in one eco system.



1.8k

My API use default module/controller/action/params url. So I can achieve what you are suggesting modifying my Bootstrap and sending every cli command to the main task of webservice module, than using that task for connecting via curl to the webservice controllers. I would have prefered to do everything avoiding external calls but it means I will user localhost address and curl in this way