【发布时间】:2018-08-03 00:44:57
【问题描述】:
我正在开发一个使用 CakePHP 3.5 构建的系统,该系统有多个全天运行的 Cron 作业。
这些 cron 作业一直以以下格式执行:
/home/myuser/public_html/bin/cake shell_name command_name
当 crons 运行时,它们通常会在服务器发送的默认系统电子邮件中输出其进度,例如:
Welcome to CakePHP v3.4.11 Console
---------------------------------------------------------------
App : src
Path: /home/myuser/public_html/src/
PHP : 5.6.31
---------------------------------------------------------------
Starting Thirty Minute Report Email Cron (JSON and PDF files)....
- Report 1 complete
- Report 2 complete
Report emails sent.
Cron Finished.
昨天,由于没有更改代码,这些 cron 已停止工作。
现在只输出 CakePHP 3.5 Shell Helper:
Welcome to CakePHP v3.4.11 Console
---------------------------------------------------------------
App : src
Path: /home/myuser/public_html/src/
PHP : 5.6.31
---------------------------------------------------------------
Current Paths:
* app: src
* root: /home/myuser/public_html
* core: /home/myuser/public_html/vendor/cakephp/cakephp
Available Shells:
[Bake] bake
[Migrations] migrations
[CORE] cache, i18n, orm_cache, plugin, routes, server
[app] console, backups, tasks
To run an app or core command, type `cake shell_name [args]`
To run a plugin command, type `cake Plugin.shell_name [args]`
To get help on a specific command, type `cake shell_name --help`
奇怪的是,如果我通过 SSH(在实时生产服务器上)运行这些命令,那么它们执行没有问题,它们也在 localhost 上执行。
我遵循 CakePHP 文档中描述的正确格式,这是我的 shell:
namespace App\Shell;
use Cake\Console\Shell;
use Cake\Core\Configure;
class TasksShell extends Shell {
/*****
*** SENDS THE REPORT EMAIL AT A THIRTY MINUTE INTERVAL
*****/
public function thirtyMinReport() {
/** CODE **/
}
}
正在运行的 cron 是:
/home/myuser/public_html/bin/cake tasks thirty_min_report
今天我也尝试了它的变体:
/home/myuser/public_html/bin/cake tasks thirtyMinReport
/home/myuser/public_html/bin/cake Tasks thirtyMinReport
php /home/myuser/public_html/bin/cake.php Tasks thirtyMinReport
cd /home/myuser/public_html && bin/cake Tasks thirtyMinReport
我在 CakePHP 网站here 上也发现了其他人也遇到了同样的问题,但是仍然没有解决。
我可以忽略什么导致无法找到 cron shell_name 和 command_name?
【问题讨论】:
-
cron在什么情况下运行?你能 su 到那个用户并以这种方式测试它吗?
-
@rtfm 都是 root 运行的,我已经登录 SSH 用 root 测试了,还是一样。
-
你测试过非蛋糕 cronjobs 吗?
-
好主意!我现在刚刚测试了一个非蛋糕 cron……执行没问题。
标签: php shell cakephp ssh cron