Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if PECL extension is present?

Tags:

php

pecl

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.

like image 830
Prof. Falken Avatar asked May 17 '13 15:05

Prof. Falken


People also ask

How do I know if PECL is 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.

How to check PHP extension version?

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.

Where is PECL installed?

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.


2 Answers

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;
    }
}
like image 172
bitWorking Avatar answered Oct 13 '22 21:10

bitWorking


get_loaded_extensions fits the bill.

Use like this:

$ext_loaded = in_array('redis', get_loaded_extensions(), true);
like image 36
Prof. Falken Avatar answered Oct 13 '22 23:10

Prof. Falken