Execute shell from controller CakePHP 3.x(从控制器 CakePHP 3.x 执行 shell)
问题描述
我在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从控制器 CakePHP 3.x 执行 shell


- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01