So I started to look for doing same with symfony 1.4 and doctrine.
Below are some of my findings and better ways to create the batch / cron jobs.
I will walk you through the steps in order to get it working properly.
Batch Instead of Web
Symfony has already set up to make it easy to create small controllers that will be run from the command line.The “/batch” directory is where you will be putting your special controller file, instead of the “/web” directory. This batch file is looks pretty much like the front controllers that go in the “web” directory. The only thing you will be leaving out is the dispatch method which starts running the controller and action. We are going to be replacing it with a line that still fires up the sfContext instance so that we have access to our database, etc.
Batch File:
- <?php
- // this file is saved as SF_PROJECT/batch/cron_example.php
- define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
- define('SF_APP', 'frontend');
- define('SF_ENVIRONMENT', 'prod');
- define('SF_DEBUG', true);
- require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
- // get the application instance
- sfContext::getInstance();
- // put whatever code you need here…
- echo "\r\n running cron job….\r\n";
Or we can also set configuration from Project configuration file as below:
require_once(dirname(__FILE__) . '/../config/ProjectConfiguration.class.php');
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
sfContext::createInstance($configuration);
Run through command prompt:
- go to your PROJECT_DEIRECTORY
- php batch/cron_example.php
- running cron job…
The Crontab File
set up the cron to run every minute and output to null.- * * * * * * php /home/me/my_project/batch/cron_example.php > /dev/null 2>&1
Thanks for taking the time to discuss that, I really feel strongly about it and love learning more on that topic. If achievable, as you gain competence, would you mind updating your blog with more information? It is highly helpful for me. WOW gold
ReplyDeleteThe information and the aspect were just wonderful. I think that your viewpoint is deep, it’s just well thought out and truly incredible to see someone who knows how to put these thoughts so well.
ReplyDeletemdf wood signs
I wholeheartedly agree with your review
ReplyDeletemdf wood signs
This is a great post ! it was very informative. I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading it. buy gold
ReplyDelete