User login

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

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

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

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • 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>
  • Lines and paragraphs break automatically.

More information about formatting options

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