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.

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

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来