After submit the form, I've got following error:

Fatal error: require_once() [function.require]: Failed opening required 'sites/all/modules/contributions/pathauto/pathauto.inc' (include_path='.;D:\wamp\bin\php\php5.2.6\pear') in D:\bro\workspace\Websites\XComKids\trunk\sites\all\modules\contributions\pathauto\pathauto.module on line 74

http://drupal.org/node/114774#module_load_include

Changed:

function _pathauto_include() {
  $pathauto_path = drupal_get_path('module', 'pathauto');
  require_once("$pathauto_path/pathauto.inc");
  require_once("$pathauto_path/pathauto_node.inc");
  require_once("$pathauto_path/pathauto_taxonomy.inc");
  require_once("$pathauto_path/pathauto_user.inc");

to:

function _pathauto_include() {
  module_load_include('inc', 'pathauto', 'pathauto');
  module_load_include('inc', 'pathauto', 'pathauto_node');
  module_load_include('inc', 'pathauto', 'pathauto_taxonomy');
  module_load_include('inc', 'pathauto', 'pathauto_user');

The same issue on 5.x: #337615: require_once failure on cron with modules that have a register_shutdown_function

Comments

apaderno’s picture

Status: Needs review » Active

I rather prefer to use module_load_include() in cases like this.

The original code doesn't work because it looks for the files in the wrong directory. The correct code should be

function _pathauto_include() {
  $pathauto_path = drupal_get_path('module', 'pathauto');
  require_once("./$pathauto_path/pathauto.inc");
  require_once("./$pathauto_path/pathauto_node.inc");
  require_once("./$pathauto_path/pathauto_taxonomy.inc");
  require_once("./$pathauto_path/pathauto_user.inc");
}

That is what module_load_include() does.

function module_load_include($type, $module, $name = NULL) {
  if (empty($name)) {
    $name = $module;
  }

  $file = './'. drupal_get_path('module', $module) ."/$name.$type";

  if (is_file($file)) {
    require_once $file;
  }
  else {
    return FALSE;
  }
}

The paths passed to require, require_once, include, and include_once should always start with ./.

greggles’s picture

Status: Active » Closed (duplicate)

We don't create multiple issues if the problem is present in multiple branches. We fix it in them all in the same issue.

Marking this a duplicate of #337615: require_once failure on cron with modules that have a register_shutdown_function.

kenorb’s picture

Yes, that's true, but we can still use module_load_include, what's for this function was created?

greggles:
thanks, but many people say to create different issues for different branches, so I'm confused now,
but it's ok.
This one: http://drupal.org/files/issues/pathauto_include_optimization.patch seems to be good solution.

In my case it was called from shutdown as well.