php - Creating Cron Jobs in CakePHP 2.x -
i have attempted create cron job in cakephp 2.x application. of resources have read online seem either doing different 1 little consistency or explain in complex terminology.
basically have created following file myshell.php
in /app/console/command
<?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 cron'); $result = $email->send('hello cron'); } } ?>
and want run code @ midnight every night.
what do next? next part confuses me! have read on book at: http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html should run code in terminal make @ time etc. , can set these using hosting provider rather seems.
but i'm rather confused console directory. should go in folder in here: https://github.com/cakephp/cakephp/tree/master/app/console
/console/command /console/command/tasks /console/templates
also noticed many of files .php (e.g. shell file .php), according documentation i've read cron jobs, executed files should .sh?
can shed more light on this?
and code call command?
e.g. presume incorrect: 0 0 * * * cd /domains/driz.co.uk/html/app && cake/console myshell sendemail
thanks
no. there no way in php. doesn't matter, because crons easy set up.
in article linked to, still have set cron - difference set single cron, runs other crons - opposed setting 1 cron per job. so, either way, have learn create cron.
the instructions depend on server's operating system , host you're with. hosts have way set cron jobs through gui interface cpanel or something, without having touch terminal.
it's pretty easy find instructions online how set cron jobs host or server os, if you're having trouble, update question host's name, , server os , version.
also ---------------------------------
often in cron jobs you'll running shell script (.sh). don't worry case; your's end in .php.
re: directory structure:
/console/command
new file should go.
if you're doing lot of shell stuff, may want abstract common code out /console/command/task
folder. read more here. won't needed in case.
/console/command/templates
can put custom templates cake bake console - don't worry now.
if i've got couple of cron jobs run, create 1 file called cronjobsshell.php, , put them in there.
really, should read cake's documentation on shells start end. give nice picture of how hangs together.
Comments
Post a Comment