CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • CiviMail installation and configuration (Moderator: Donald Lobo) »
  • CLI version of v. 2.2 CiviMail cron job?
Pages: [1]

Author Topic: CLI version of v. 2.2 CiviMail cron job?  (Read 4272 times)

EvanDonovan

  • Guest
CLI version of v. 2.2 CiviMail cron job?
May 18, 2009, 02:10:38 pm
Is there a command line version of civimail.cronjob.php for CiviCRM 2.2? We really would prefer not to run it through the web server because it increases load significantly and can require messing with PHP timeout values, etc.

If there is no CLI version available, what would I need to modify to get it to run on the command line? Currently when I try to run it through PHP, it gives me a "failed to open stream" error. I think that it's not initializing the CiviCRM include path properly.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CLI version of v. 2.2 CiviMail cron job?
May 18, 2009, 02:45:57 pm

There is no CLI version, but i think it should be easy to get it up and running via CLI. The main thing would be to ensure that the civicrm.settings file gets loaded properly. Where are u getting the "failed to open stream" error? You can hop on IRC and we can help out

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

EvanDonovan

  • Guest
Re: CLI version of v. 2.2 CiviMail cron job?
May 27, 2009, 01:01:54 pm
Thanks for your help. Sorry I didn't see your message sooner; I thought the forum would notify me of a reply or something.

What is the IRC channel for CiviCRM? I've tried #civicrm on freenode before and didn't find anything.

UPDATE: It worked when I went to irc://irc.freenode.net/civicrm on ChatZilla; earlier I had tried the Join channel... command and it hadn't worked. Anyway, I will be on later when I get around to this problem again - some other things have come up since then.
« Last Edit: May 27, 2009, 03:30:16 pm by EvanDonovan »

EvanDonovan

  • Guest
Re: CLI version of v. 2.2 CiviMail cron job?
May 28, 2009, 09:11:24 am
Ok, I created a command line version of the CiviMail cronjob, which I called civimail.cli-cronjob.php. Below is the code:

Code: [Select]
require_once 'cli.php';

$cli = new civicrm_cli ();

function processQueue( ) {
    require_once 'CRM/Mailing/BAO/Job.php';
    CRM_Mailing_BAO_Job::runJobs();
}

processQueue( );

And here is how to call it (i.e., from a crontab):

Code: [Select]
Usage: $ php5 /sites/all/modules/civicrm/bin/civimail.cli-cronjob.php -k key -u user -p password -s yoursite.org
Note that in order to get it to work, I had to make two changes to cli.php in the civicrm/bin directory. I had to change the $include_path line to the following:

Code: [Select]
$include_path = "/path/to/public_html/sites/all/modules/civicrm/packages/";
set_include_path( $include_path );

Otherwise I got a PHP error saying that I could not declare the PEAR functions twice.

Also, I had to change the require_once in setEnv() to

Code: [Select]
require_once ("../civicrm.config.php");
Otherwise, it was looking for the civicrm.config.php in the same directory as cli.php, instead of in the next level up.

Anyway, it would be great if you could review this code so it could possibly get included in the next release of CiviCRM. I think others might appreciate having a CLI version of the CiviMail cron.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CLI version of v. 2.2 CiviMail cron job?
May 28, 2009, 10:39:38 am

hey evan:

cool that u got it to work. Want to file an issue and submit a patch along with ALL your changes

thanx

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

EvanDonovan

  • Guest
Re: CLI version of v. 2.2 CiviMail cron job?
May 28, 2009, 12:18:47 pm
Sure. Is there a guide somewhere to how I would do that? I know how to file issues on Drupal.org, but not on CiviCRM.

Also, I don't know how to create a patch in Unix that adds a file. How do you do that?

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: CLI version of v. 2.2 CiviMail cron job?
May 28, 2009, 01:53:41 pm

1. http://issues.civicrm.org/ is the place to file issues and patches

2. i think if you do a unified diff (diff -u) across 2 directory structures, it will create a diff file that includes any new files

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

EvanDonovan

  • Guest
Re: CLI version of v. 2.2 CiviMail cron job?
May 28, 2009, 04:16:07 pm
Thanks again! I may get around to that next week.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • CiviMail installation and configuration (Moderator: Donald Lobo) »
  • CLI version of v. 2.2 CiviMail cron job?

This forum was archived on 2017-11-26.