Check For Loaded PHP Extensions

Written by

in

,

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


$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;
 }
}

Comments

Leave a Reply

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