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

By Benjamin Melançon
on 14 Mar
0 comments

Key words and phrases

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

Tags

Description

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).

 

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup> <kbd> <s>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.