cakephp 3 Cron作业无法在cpanel中使用
问题描述:
我正在尝试在cakephp 3 shell脚本中实现cron作业,但在cpanel中不起作用.
I am trying to implement cron job in cakephp 3 shell script but it is not working in cpanel.
下面是我的cron工作代码blog is my cakephp 3 folder
below is my cron job code blog is my cakephp 3 folder
cd/home/mmentert/public_html/abc.com/blog&& bin/cake hello main
cd /home/mmentert/public_html/abc.com/blog && bin/cake hello main
Cakephp 3 shell类文件
Cakephp 3 shell class file
namespace App\Shell;
use Cake\Console\Shell;
use App\Controller\UsersController;
class HelloShell extends Shell {
public function main() {
$userinfo=new UsersController();
$data=$userinfo->useremail();
$this->out($data);
}
}
答
我假设您使用的是共享托管,CakePHP 3 Docs上建议的语法不适用于共享托管,这对我来说是有效的
I assume you are using shared hosting, the syntax suggested on CakePHP 3 Docs does not work for shared hosting, this is what worked for me
php -q -d register_argc_argv=on /home/public_html/bin/cake.php app main
请使用您自己的cake.php文件路径
Please use your own path for cake.php file
- -q --no-header安静模式.禁止HTTP标头输出(仅CGI).
- -d --define为php.ini中允许的任何配置指令设置自定义值
希望有帮助.