How can I find out which extensions are being used by a codebase in PHP?

I am trying to develop server requirements files for an existing codebase.

For this I need to determine what extensions I need to run this codebase,

Since the code base is too big to check one by one for each function. I am thinking about using the name extension to determine what extensions are used in the code.

i.e 
openssl_open -> means openssl is required
mcrypt_store -> means mcrypt is required.

      

Will this work? Is there a better way to do this?

Some people suggest using "get_loaded_extensions", but that is not the answer to the question I am asking.

It is also not possible to parse each feature manually, because that would be roughly at least 3000+ features in the codebase.

I want to know what extensions are used in the code database, not a list of extensions installed on the server.

+3


source to share


1 answer


I would suggest the following: use a PHP tokenizer like, token_get_all

or Python for NikiC PHP to tokenize each source file, iterate over to find all function calls, and test those functions using.Don't ReflectionFunction::getExtension

forget to do the same for classes. This should be a small enough script that can take an inventory of all the extensions / features in use in your codebase, which will also list extensions that you don't currently see (since they can't be reflected).



This will skip functions called by name, for example call_user_func('mcrypt_store')

; but a) you can mark and manually check usage call_user_func

, etc., and b) hopefully not all uses of the extension are coded like this.

0


source







All Articles