How to automatically determine which PHP extensions are used by a project?

Is there a way to automatically find out which PHP extensions are used by a particular project, do you have source code?

When porting a website from one server to another, I often wonder what PHP extensions should be enabled for the site to function properly. Yes, this use case probably does not matter if the project used Docker or had a comprehensive installation guide, but this is not always the case.

I was thinking of a script that went through all .php files and looked for specific function calls or classes, for example:

  • new mysqli(or mysqli_connect(: mysqli
  • imagecreate(or imagepngor imagejpegor ...: gd
  • curl_init(: curl

Is there a similar script? If not, would it make sense to write it?

+4
source share
1 answer

Record as response to OP request in their comment

glenscott / php dependencies

Although this is not a complete solution, it will reduce the manual work you will need to do: https://github.com/glenscott/php-dependencies

A few caveats:

  • The source code and its dependencies should be under one directory - files that are outside of this directory are not included / included.
  • It is based only on function dependencies. This means that class dependencies are not checked.

You can read the blog post from the author: http://www.glenscott.co.uk/blog/finding-function-dependencies-in-your-php-applications/

For start

You can do this through the command line or through a web browser.

  • 1) PHP: php get-env-functions.php

  • 2) : php scan-dependencies.php

+1

Source: https://habr.com/ru/post/1618266/


All Articles