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) »
  • Failed opening 'bin/cli.php' when run as cron job
Pages: [1]

Author Topic: Failed opening 'bin/cli.php' when run as cron job  (Read 2145 times)

planigan

  • I post occasionally
  • **
  • Posts: 37
  • Karma: 1
    • Allegheny CleanWays
  • CiviCRM version: 4.1.0
  • CMS version: Drupal 6.24
  • MySQL version: 5.0.90
  • PHP version: 5.2.13
Failed opening 'bin/cli.php' when run as cron job
January 31, 2011, 01:05:11 pm
Hi,

I want to run civimail.cronjob.php using php cli and a cron job. I have a strange problem though...

When I manually run the following command, everything works fine.
Code: [Select]
cd /home/mysite/public_html/main/sites/all/modules/civicrm && php -dmemory_limit=128M  bin/civimail.cronjob.php -u myuser -p mypass -s default

However, when I run the exact same command as a cron job, it fails and I get the following in my error_log.

Quote
Warning: require_once(bin/cli.php) [function.require-once]: failed to open stream: No such file or directory in /home/alleghen/
public_html/drupal-6.20/sites/all/modules/civicrm/bin/civimail.cronjob.php on line 70
Fatal error: require_once() [function.require]: Failed opening required 'bin/cli.php' (include_path='.:/usr/lib/php:/usr/local/lib/php'
) in /home/alleghen/public_html/drupal-6.20/sites/all/modules/civicrm/bin/civimail.cronjob.php on line 70

I actually tried inserting a getcwd() on line 70 of civimail.cronjob.php, and it returns '/home/mysite/public_html/main/sites/all/modules/civicrm' as expected when run manually, but '/home/mysite/public_html/main/sites/all/modules/civicrm/bin' when executed from cron.

Any idea why cron is causing the working directory to be civicrm/bin instead of civicrm?
« Last Edit: January 31, 2011, 01:58:40 pm by planigan »

planigan

  • I post occasionally
  • **
  • Posts: 37
  • Karma: 1
    • Allegheny CleanWays
  • CiviCRM version: 4.1.0
  • CMS version: Drupal 6.24
  • MySQL version: 5.0.90
  • PHP version: 5.2.13
Re: Failed opening 'bin/cli.php' when run as cron job
January 31, 2011, 01:21:33 pm
For what it's worth, the same thing seems to happen whether I replace the '&&' in the above command with a ';' or put each command on a separate line in a shell script and then execute the script.

I managed a workaround by adding
Code: [Select]
chdir(dirname(__FILE__).'/../'); to the civimail.cronjob.php file, but I realize that's a hack.
« Last Edit: January 31, 2011, 02:00:28 pm by planigan »

planigan

  • I post occasionally
  • **
  • Posts: 37
  • Karma: 1
    • Allegheny CleanWays
  • CiviCRM version: 4.1.0
  • CMS version: Drupal 6.24
  • MySQL version: 5.0.90
  • PHP version: 5.2.13
Re: Failed opening 'bin/cli.php' when run as cron job
January 31, 2011, 08:54:03 pm
OK, I think I might have this one figured out. It appears as though cron is using a different php binary than what is called manually from the shell!

Executing which php && php -v from the command line gives me this:

Quote
/usr/local/bin/php
PHP 5.2.13 (cli) (built: May 14 2010 11:25:55)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by ionCube Ltd., and
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

Executing which php && php -v from cron gives me this:

Quote
/usr/local/bin/php
PHP 5.2.13 (cgi) (built: May 14 2010 11:33:31)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
    with the ionCube PHP Loader v3.3.20, Copyright (c) 2002-2010, by ionCube Ltd., and
    with Zend Optimizer v3.3.9, Copyright (c) 1998-2009, by Zend Technologies

I guess cron's path is setup differently than my shell, so it is taking the CGI version of the php executable instead of the CLI version. The key difference here is that the CGI version changes the working directory to that of the script (see http://php.net/manual/en/features.commandline.differences.php).

So, there are two ways to fix this. Either (a) specify the full path to the CLI php executable (e.g., /usr/local/bin/php) in cron or (b) try to use the --no-chdir or -C switch with the CGI executable. I chose (a), although (b) might be more compatible with other systems seeing as the --no-chdir switch is supposedly included with the CLI executable for backward compatibility.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • CiviMail installation and configuration (Moderator: Donald Lobo) »
  • Failed opening 'bin/cli.php' when run as cron job

This forum was archived on 2017-11-26.