我在 CakePHP Shell 中有一项特定任务,它由 CRON 作业执行.但我希望用户能够随时从网络界面(如按钮或类似的东西)执行它.
I have a specific task in a CakePHP Shell and it's executed by a CRON job. But I want the users to be able to execute it from a web interface (like a button or something like this) whenever he wants.
所以,我的问题是,这是否可以从控制器执行 shell?
So, my question is, is this possible to execute a shell from a controller ?
在控制器中模拟:
bin/cake MyShell
我知道在以前版本的 CakePHP 中是可能的,但是我在最新版本中没有找到与此相关的内容.使用 exec("bin/cake MyShell") 对我来说似乎很脏.
I know it was possible in the previous versions of CakePHP, but I didn't find something related to this in the newest version. And use exec("bin/cake MyShell") seems really dirty to me.
创建一个shell对象,调用它的任何一个要执行的函数
create a shell object , the call any of its function to want to excute
$myShell = new AppShellMyShell;
$myShell->anyShellFun();
这篇关于从控制器 CakePHP 3.x 执行 shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!