Check For Loaded PHP Extensions

Sometimes you want to make sure a certain php extension is loaded or not. These extension can be curl, xmlrpc, or ldap. After all when you move your application from one server to another the configuration not necessarily the same. So here how you do check for loaded or existing php extensions using get_loaded_extensions().


1
2
3
4
5
6
7
8
9
10
$extNeeded = array('ldap', 'mysql', 'xmlrpc','ron_ext');
$loadedExtension = get_loaded_extensions();
foreach($extNeeded as $ext){
 if(!in_array($ext, $loadedExtension)){
  echo 'The application cannot start properly, '.$ext.' extension is missing.
  The following extensions are needed: '
.implode(', ', $extNeeded).'.
  Terminating application ...'
;
  die;
 }
}
This entry was posted in php, Web Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


− 1 = seven