How do I from PHP code if a PECL extension is installed or not?
I want gracefully handle the case when an extension is not installed.
To determine if a particular PECL module is installed and enabled, you will want to create a phpinfo page and check for the specific PECL module you are looking to use in your PHP code. For step-by-step instructions on creating and using a phpinfo page, please see our article Viewing PHP Settings Using a phpinfo Page.
Check PHP Version by Running PHP Codephp echo 'PHP version: ' . phpversion(); Create the file using a text editor like gedit or Notepad, and upload it to your website's document root directory. Note: While phpinfo() is useful for debugging, the page features sensitive information about your system.
The module will be installed in /usr/lib64/php/modules/ as /usr/lib64/php/modules/uploadprogress.so. NOTE: Place under the"Dynamic Extensions" section! If you are using FastCGI, edit the domain's "php.
I think the normal way would be to use extension-loaded.
if (!extension_loaded('gd')) {
// If you want to try load the extension at runtime, use this code:
if (!dl('gd.so')) {
exit;
}
}
get_loaded_extensions fits the bill.
Use like this:
$ext_loaded = in_array('redis', get_loaded_extensions(), true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With