dongwo5110 2013-10-10 20:13
浏览 64
已采纳

在Media Temple网格服务上运行CakePHP Cron作业

I have the following Shell in my CakePHP app:

<?php 

class MyShell extends Shell {

    public function sendEmail() {

        App::uses('CakeEmail', 'Network/Email');

        $email = new CakeEmail();

        $email->from('cameron@driz.co.uk');

        $email->to('cameron@driz.co.uk');

        $email->subject('Test Email from Cron');

        $result = $email->send('Hello from Cron');

    }

}

?>

Which I am trying to run every 5 minutes as a test on my Media Temple Grid Service host.

/home/####/domains/driz.co.uk/html/app && Console/cake my_shell send_email 

cd /home/####/domains/driz.co.uk/html && Console/cake my_shell send_email 

cd /home/####/domains/driz.co.uk/html/app && Console/cake my_shell send_email 

php /home/####/domains/driz.co.uk/html/app/Console/Command/MyShell.php

I have tried ALL of the above but none of them work... Any ideas why?

(Note: that the times are missing as you specify these in the admin panel separate to the actual command)

Has anyone got any experience running CakePHP cron jobs on Media Temple? I have asked MT support, and they explained that the first 3 lines wouldn't work because they are not direct commands to the files (so apparently the CakePHP docs are for the terminal only).

  • 写回答

1条回答 默认 最新

  • douzhong8856 2013-10-10 20:36
    关注

    Here's what I did to get it working:

    Modified your email script to include some output:

    class MyShell extends Shell {
        public function sendEmail() {
            App::uses('CakeEmail', 'Network/Email');
            $email = new CakeEmail();
            $email->from('user@domain.com');
            $email->to('user@domain.com');
            $email->subject('Test Email from Cron');
            $result = $email->send('Hello from Cron');
            $this->out('Email sent successfully.');
        }
    }
    

    Next, I tested via console to ensure it would work. For the above code, the "Shell" suffix in "MyShell" is omitted per the docs and the second parameter is the function name. Here was the CLI command that worked for me from the root of the application, /home/#####/domains/mydomain.com/html/cake/cakephp/app.

    Console/cake my sendEmail
    

    Output:

    Welcome to CakePHP v2.4.1 Console
    ---------------------------------------------------------------
    App : app
    Path: /nfs/c##/h##/mnt/#####/domains/mydomain.com/html/cake/cakephp/app/
    ---------------------------------------------------------------
    Email sent.
    

    My value in the command box in the MT (gs) dashboard was constructed according to this. It includes:

    cd 'app_root' && Console/cake 'class_name_sans_shell' 'function_name'
    

    For the above code, that results in:

    cd /home/#####/domains/mydomain.com/html/cake/cakephp/app && Console/cake my sendEmail
    

    It's worth noting that "Console/cake" is our executable in this case so that's the program we are running.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿