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) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Cannot redeclare class pear...
Pages: [1]

Author Topic: Cannot redeclare class pear...  (Read 1138 times)

torrance123

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 3
  • CiviCRM version: 4.0
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.3.3
Cannot redeclare class pear...
October 22, 2012, 09:16:01 pm
We are running into issues on our system where a Drupal module is calling 'include_once PEAR.php' and then civicrm is doing the same, triggering the above error 'Can redeclare class pear'.

The issue here is that at the time the drupal module includes pear, the php includes path is limited strictly to system paths, including the standard system version of pear. However, by the time civicrm attempts to include pear, the includes path has been modified to include civicrm's own bundled version of pear. Since these files appear new, the call to include_once() attempts to re-include pear.

So the issue here is a bit of a race condition: we need civicrm to modify the includes path before any other module has a chance to 'include_once PEAR.php'.

Assuming Drupal modules do their work within hooks and not globally, it might be enough to simply call 'civicrm_initialize()' within a 'hook_init()' in civicrm (this works for our particular use case). Is there are great cost calling civicrm_initialize() on every page load?

Or are there better ways to deal with this issue? Have other people had this come up before?

« Last Edit: October 22, 2012, 09:17:42 pm by torrance123 »

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Re: Cannot redeclare class pear...
October 23, 2012, 07:33:21 am
Quote from: torrance123 on October 22, 2012, 09:16:01 pm
Assuming Drupal modules do their work within hooks and not globally, it might be enough to simply call 'civicrm_initialize()' within a 'hook_init()' in civicrm (this works for our particular use case). Is there are great cost calling civicrm_initialize() on every page load?

Anecdotally, I've heard contradictory experiences. It probably depends on the web site's workload. If the site is used primarily as a "back office" system for accessing CiviCRM, then calling civicrm_initialize() from hook_init() won't make a difference. If the site only gets a couple concurrent users at a time, then it won't make a difference. But if the site processes a high-volume of requests for Drupal content (without an intermediary like a CDN or Varnish), then it could add up.

Quote from: torrance123 on October 22, 2012, 09:16:01 pm
Or are there better ways to deal with this issue? Have other people had this come up before?

If it matters in the workload, then you might try setting the system's default include-path to reference the CiviCRM packages directory. To be safe, the path should exactly match the path that civicrm_initialize() would construct. But I've never tried this.

In a past case where I needed a Drupal module to access the CiviCRM packages, I just hacked the Drupal module to call civicrm_initialize() right before the 'require_once'. But this was an in-house module, and you probably don't want to hack that into a third-party module.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Cannot redeclare class pear...
October 23, 2012, 09:04:20 am
Hi,

A quick an dirty workaround is to delete the classes from the civicrm/packages folder and symlink them to the "main" pear location.

Code: [Select]
!/bin/sh
set -e

for i in Mail Mail.php PEAR.php ; do
    rm -rv packages/$i
    ln -sv /usr/share/php/$i packages/
done
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

torrance123

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 3
  • CiviCRM version: 4.0
  • CMS version: Drupal 7
  • MySQL version: 5.0.91
  • PHP version: 5.3.3
Re: Cannot redeclare class pear...
October 23, 2012, 02:17:01 pm
Is it possible to pull out the logic that parses the civicrm.settings.php file from civicrm_initialize() into a more lightweight function? We just want to have civicrm's global constants, etc. defined and the includes path modified — we don't need any of the other civicrm infrastructure initialized.

I can go the dirty hack route, etc., but would be happier to get a cleaner solution if I can.

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: Cannot redeclare class pear...
October 23, 2012, 03:13:56 pm

Do you want to file an issue and an associated patch since u've done the work :)

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

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Cannot redeclare class pear...

This forum was archived on 2017-11-26.