User login

Which is faster to check, Drupal's module_exists or PHP's function_exists?

Searched words: 
drupal which is faster module_exists or function_exists better performance of checking for existence and enabled module versus function in PHP

Which is faster (better performance) - module_exists or function_exists?

Based on the fact that module_exists -
http://api.drupal.org/api/function/module_exists/5
- calls a Drupal function http://api.drupal.org/api/function/module_list/5 - that could even call a database query,
AND a PHP function -
http://php.net/array_key_exists
- we're going to go with function_exists.

But with the static caching perhaps this is worth taking the trouble of benchmarking?

But function_exists also protects us (in terms of total site breakage) against api changes.

<?php
if (function_exists('bio_for_user')) {
 
$nid = bio_for_user($uid);
 
$node = node_load($nid);
 
// more stuff here
}
?>

Aside: I wonder if bio.module's bio_for_user function should be statically cached. I think it should.

Further aside: the "more stuff here" part got pretty interesting, in terms of how do we load a node into the theming layer ourselves (that is, when none of the ways Drupal provides are available).

Resolution

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Internal paths in single or double quotes, written as "internal:node/99", for example, are replaced with the appropriate absolute URL or path. Paths to files in single or double quotes, written as "files:somefile.ext", for example, are replaced with the appropriate URL that can be used to download the file.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.