What php modules are used by my app - php

Is there a way I can find out what modules are being used by my php application without going through thousands of lines of code?
I can get the whole list of PHP modules on current server via php -m, but I want to know if there is any way to find out modules required by my app in particular.

There is a PEAR package called PHP_CompatInfo that does something like that:
Find out the minimum version and the extensions required for a piece of code to run
It's marked as no longer maintained, so there might be some problems using it with recent versions of PHP

You should look into using get_loaded_extensions() or extension_loaded().

Related

Does PHP have a built-in means of determining the oldest PHP version compatible with a given PHP script? Or will it ever?

I wish to be able to do something like:
php --determine-oldest-supported-php-version test.php
And get this output:
7.2
That is, the php binary checks test.php for all function calls or syntax used, and then spits out the oldest version of PHP which would be able to run the script.
The purpose would be for me to create a script which goes through all the .php files in my library/framework and figures out which version of PHP I should consider to be the "oldest supported version".
Currently, I'm doing this manually. Whenever I knowingly use a new feature, function or syntax, I bump up a variable to "7.4" or whatever, and then compare the currently used PHP version against that on runtime. This is not ideal, as you can imagine, and I could very well forget to bump up this value or bump it up too much, or too little, etc.
It would be much nicer to be able to determine this automatically, with such a feature in PHP itself.
I have of course looked through the list of options and PHP has no such feature as far as I can tell. Since I basically answered my own question right away, are there any plans on such a feature in the future?
The only guarantee given is that PHP will remain compatible within the same major version.
You may be interested in looking at the article
Why You Should Be Using Supported PHP Versions.
The tool you are looking for is the GitHub project
PHP_CodeSniffer,
further described in the article
PHPCompatibility update.
You may run it using a command such as:
phpcs --standard=PHPCompatibility --runtime-set testVersion 5.4 <path-of-your-php-files>

Compile PHP using shared option and directory location

I cannot figure out the proper ./configure options to use when giving the configure command if I would like to have something be shared (thus creating an .so extension) as well as stating a directory where required libraries are.
Example:
--with-openssl=shared will create a .so file
--with-openssl=/home/username/local will compile directly into the php build.
How do I state both? I see this nowhere in the php docs.
I am installing on a linux Ubuntu.
Well, I found it through trial and error as well as a few other posts of people going through different troubles that had their ./configure commands visible.
In my example case there are two flags you need:
--with-openssl=shared --with-openssl-dir=/home/username/local
In other instances there is no extension-name-dir flag, so you do comma separated values:
--with-cron=shared,/home/username/local
I could find no easy way to tell you which ones are which, but trial and error got me through these two that I needed. In the case of GD you actually need as many as four separate ones for the needed library support:
--with-gd=shared --with-jpeg-dir=/home/username/usr --with-png-dir=/home/username/usr --with-freetype-dir=/home/username/usr
Hope this helps someone else, I could find no other discussions about this issue (hard to believe there was no SO answers already).

What is the best way to build php from source CentOS

I am building php from source on a new CentOS box and as usual I have to wrangle up all the various configuration options I might need. This gets tricky because there are various extensions that I want and certain options that I always for get to put in the .configure script. Not only that but PHP 5.3 has has different defaults for various options.
Is there an interactive or annotated version of the configure script somewhere or a good set of defaults to reference?
Thanks!
Grab the existing PHP SRPM, update the spec with the new version, release, and tarball, and rebuild.

Is there a way to determine the minimum version of PHP required to run a script automatically?

I know of http://pear.php.net/package/PHP_CompatInfo - however I am looking for a online service that offers something similar, or perhaps better.
I have noticed that PHP_CompatInfo has not been updated in some time (2009-01-19)
I would like to be able to upload a set of files, or if needed, one at a time, and receive data back on what the expected minimum version of PHP is required to run those files.
Until now, I have simply scraped all functions from my files, and then done look-ups on php.net to see what version would be needed for example:
filter_var
(PHP 5 >= 5.2.0)
PHP_CompatInfo2 is under development, see the announcement on the PEAR developer list.
See http://php5.laurent-laville.org/compatinfo/

Can you use scons to build PHP extensions?

The standard way of writing PHP extensions is to use autoconf/automake alongside a script called phpize, which seems to generate your autoconf configuration based on a template that's specific to your PHP environment. This let's it build the PHP extension for the right version of PHP, etc.
autoconf and the m4 language that is used to configure it is arcane, and people have written alternatives, such as scons. I want to be able to use one of these when building a PHP extension.
In principle, you should be able to use scons or similar tools to build PHP extensions. However, I can't see how you would replace the phpize step.
Has anyone had any success in building PHP extensions with scons, or another more modern build tool?
The path of least resistance would be to have SCons run autoconf, phpize and whatever else is needed for your PHP extension. You may be able to extract the compiler configuration out of there and let SCons do the actual building, or you can simply have SCons run "make".
Declaring shell command targets from SCons is easy, but getting dependencies right is always tricky.
Basically you will have to let SCons know of any intermediate file produced by these external tools. This way it can not only properly clean them, but it can also cache the whole series of steps based on the content signature of each intermediate result (MD5 checksum).
Proper caching will significantly reduce the number of times these external tools will actually need to be invoked as the code base changes.
While I don't think somebody has written a specific solution for PHP, there are lots of custom builders on the SCons wiki that do similar things.
phpize(1) is just a shell script, so i guess you could modify it to work with scons...

Categories