Command to show/check required PHP version and exts #4658

mishak87 opened this Issue Dec 1, 2015 · 7 comments


None yet

4 participants

mishak87 commented Dec 1, 2015

Composer is not very friendly when it comes to generating matching environments for application.

composer show -i -t | grep -o "\-\-\(ext-\|php\).\+" | sort | uniq | cut -d- -f3-

That command gives me list of all required versions of all extensions and php like this:

ext-curl *
ext-iconv *
ext-pdo *
ext-tokenizer *
php >= 5.3.0
php >=5.3,<8.0-DEV
php >=5.6

It still needs bit of parsing and sorting to get all information for building matching environment.

Make composer more machine friendly (CI, CD etc.)

  1. Add command to check if all ext/php version requirements are satisfied.
    It would help if composer could check if all extensions and php are matching (non destructive way). So far this is done only on install or update (destructive operations) and only if some dependency has changed or is missing.
  2. Add command to list all ext/php version requirements.
    Provide list of final version restrictions per ext/php.
@alcohol alcohol added the Feature label Dec 3, 2015
alcohol commented Dec 3, 2015

Composer already checks php/ext requirements. You simply put them in your "require" section. So, not really sure how that doesn't address your concerns already. Please do elaborate.

See also

mishak87 commented Dec 3, 2015

Thanks I noticed platform packages when researching this issue further.

AFAIK platform requirements are only checked for installs and updates of affected packages, please correct me if that's not the case.

I am trying to create CI process using docker. Having image with minimal set of extensions reduces build time and size of image compared to generic image.

I would like to use just composer.lock to detect if image matches requirements without installing anything. (for checking if image matches requirements)
Second use-case is to collect platform requirements in aggregated form (one set of min, max constraints instead of N) for building image.

Flow looks like this:

  1. Project is installed using secrets in PHP cli only image ignoring platform requirements except PHP of course.
  2. Tailored image is build based on requirements.
  3. Tailored image is checked if matches platform requirements.
  4. Result is copied to tailored image.

By requirements I mean facts collected from composer.lock require packages sections.

alcohol commented Dec 3, 2015

Composer was not built to manage php extensions, but there is a PR open that attempts to fill this gap. That still does not quite resolve your use-case though. If this is something you need, you will have to contribute it yourself.

mishak87 commented Dec 3, 2015

Tagging #3836 we share same need for machine readable set of aggregated constrains
I am ok with writing pull but have to read more code first.

Seldaek commented Dec 3, 2015

Ping @dzuelke because he did a lot of stuff relating to this for Heroku builds.

@Seldaek Seldaek added this to the Low-Prio / Controversial milestone Apr 19, 2016
Wirone commented Feb 7, 2017

I am interested in this feature, here's use case:

  • We define our platform requirements (php, ext) in require
  • We use external vendors, each of them can define its platform requirements
  • composer.lock is generated
  • In our organization we have to list all requirements when we order new machine for our app, so at this point I would like to be able to list all platform requirements which should be met on target platform, so I can make sure everything will be installed in order to work. Since I work with many apps and have many extensions installed it is likely to miss some of the requirements from vendors because they can be satisfied by my localhost without my knowledge. But when we prepare requirements for production machine we need to make sure that we list all platform dependencies.

@mishak87's command did the trick after some tweaks:

composer show -t | grep -o "\-\-\(ext-.\+\|php \).\+" | sort | uniq | cut -d- -f3-

(-i is deprecated and it was listing php* packages like phpunit/phpunit), but it would be really helpful to print resolved platform requirements (minimum/maximum PHP version and so on) in user-friendly way.

Wirone commented Feb 7, 2017 edited

@Seldaek it is even harder on Windows with Cygwin. Command presented above does not work since grep does not handle (U+2500 : BOX DRAWINGS LIGHT HORIZONTAL used by Composer's dependency tree) as -, also control codes must be removed before grepping. So I ended up with:

composer show -t | remove_control_codes | sed 's/─/-/g' | grep -o "\-\-\(ext-.\+\|php \).\+" | sort | uniq | cut -d- -f3-

where remove_control_codes is an alias for:

sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"

(found somewhere when I was having issues with git log output).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment