cron job with CakePHP

最后都变了- 提交于 2019-11-29 08:47:44
Nidhin Baby

I have done it in different way,

Please see the steps, it may helpful for others..

Cron/Shell Using Cakephp Framework Structure:

  1. create

    F:\websites\projectname\app\vendors\shells\filename.php

    class ClassName extends Shell {
        //var $uses = array('Post'); //name of Model
    
        //Main function runs always when shell executes
        function main() {
            mail("nidhin@2basetechnologies.com","Test","Test");
        }
    }
    

2.set 754 permission to F:\websites\projectname\cake\console\cake

  1. Set cron job as /home4/enventur/public_html/pennystock/cake/console/cake -app "/home4/enventur/public_html/pennystock/app" ClassName >/dev/null 2>&1

    /dev/null 2>&1: for Suppressing warning/error/msg from server

Thank you Nidhin

deizel

Sounds like PHP cannot find the file you specified. Check that the path is correct. For example:

# incorrect path
/home4/enventur/public_html/pennystock/cron_dispatcher.php

# correct path (?)
/home4/enventur/public_html/pennystock/app/cron_dispatcher.php

Now, this next part doesn't directly answer your question, but it's worth noting that CakePHP shells are intended for this exact purpose.

If you created a shell called Mailer and copied your UsersController::test() code to MailerShell::test(), you would call that from cron like this (again, check the paths are correct):

/home4/enventur/public_html/pennystock/cake/console/cake -app /home4/enventur/public_html/pennystock/app mailer test

With this approach, you wouldn't have to use cron_dispatcher.php as noted in that ancient Bakery article (written for CakePHP 1.1 on Christmas 4 years ago).

The cron job is a long running process that executes commands at specific dates and times.

Go to your domain cpanel account.

First make the file which you want to run the code using cron job. and upload the file on your website root folder.

Now Go to "Cron job" section in your cpanel account and enter the file path in textbox and set the time shedule which you want to run the file.

Thanks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!