while building a newsletter app in symfony I had to write a batch process, unfortunately there isnt enough documentation for doing that on the symfony website. However I would just get the following error:
unagi:htdocs rajatpandit$ symfony init-batch backend prod mailer [Exception] The specified batch "backend" does not exist.
Digging in the code, I figured out that the correct syntax is:
unagi:htdocs rajatpandit$ symfony init-batch default mailer backend >> file+ /Users/rajatpandit/websites/edu/htdocs/batch/mailer.php >> tokens /Users/rajatpandit/websites/edu/htdocs/batch/mailer.php
where:
- default: Default skeleton for the batch script
- mailer: Name of the batch script that you want to create
- frontend: Name of the application under which you want to create the batch file.
The newly created batch script is created under the folder /batch folder


I like the layout here, anyways, my blog is dofollow, come get a link. Bobby.
Hi!
Thanks for this tip!
In the symfony book, it’s written:
” The symfony CLI offers an init-batch task, which automatically creates a skeleton similar to the one in Listing 6-3 in the batch/ directory. Just pass it an application name, an environment name, and a batch name as arguments.”
on the page: http://www.symfony-project.org/book/1_0/06-Inside-the-Controller-Layer#Batch Files
Thanks to your post, I didn’t have to search the code to understand the arguments needed by the init-batch script.
Thanks a lot!
Dave
Hi Rajat,
How do I run these batch scripts?
Can I run these from the command prompt using :
>php batch/FileName.php
or Should I use cron to run them ?
Please explain.
Thanks.
Suresh
hi Suresh,
I suppose you can, in my current implementation i just used php code.
$php_path = sfConfig::get(‘app_php_path’);
$script_path = SF_ROOT_DIR . DIRECTORY_SEPARATOR . ‘batch’ . DIRECTORY_SEPARATOR . ‘mailer.php’;
$full_exec_command = $php_path .’ -q ‘ . $script_path;
// invoke the newsletter
exec($full_exec_command, &$output);
you can call it via php if you need to call it once in a while or put in a cron file if you need to do it periodically, its pretty much down to you. hope that answers your question.