0

I was asking myself if it is possible to check php files for required extensions like php-gd or php-xml. I'd like to identify all prerequisites to run a certain script.

I hope anyone can help.

Thanks in advance.

Best regards, christian

3 Answers3

2

You can use extension_loaded:

if(extension_loaded('gd'))
{
    echo 'GD Library found';
}

Alternatively, you can use get_loaded_extensions(), which will return an array.

BenM
  • 52,573
  • 26
  • 113
  • 168
  • For this solution I would have to know which extension is required and then can check if it is loaded, right? I'd like to do it the other way around. I don't know which extensions are required to run the code and that's what I like to find out so I can install them. –  Nov 15 '13 at 10:53
  • You cannot achieve that. – BenM Nov 15 '13 at 11:17
0
<?php
    if (extension_loaded('gd') && function_exists('gd_info')) {
        echo "PHP GD library is installed on your web server";
    }

    if (extension_loaded('xml')) {
        echo "PHP XML installed on your web server";
    }
?>

See also

<? print_r(get_loaded_extensions());?>
0

You can use PhpCodeAnalyzer to static analyze your code to finds usage of PHP extensions.

Manuel
  • 836
  • 13
  • 30