Yii 2.0: Boost composer-asset-plugin update speed

5 followers

If you're using a lot of bower and npm assets with Yii 2.0 you might encounter long running composer update tasks.

Luckily this issue can be avioded with the recently released version 1.2.0 of fxp/composer-asset-plugin, which can be confiugred to use native git instead of GitHub REST-API calls. You can read more about the details in this issue.

TL;dr

To enhance the speed composer you first need to update the asset-plugin

composer global require fxp/composer-asset-plugin:^1.2.0

In your project's composer.json add the following settings to the extra section

"extra": {
    "asset-vcs-driver-options": {
        "github-no-api": true
    },
    "asset-pattern-skip-version": "(-build|-patch)"
},

Now you are ready to run

composer update -vv

While your very first run might take a while, due to cloning git-repositories, all subsequent updates should be blazingly fast now!

See also Use no-api option of VCS Githhub driver...

Bonus "prestissimo plugin"

To further improve speed you can also install this wonderful plugin, called prestissimo.

Bonus "Docker"

To use this new feature during local Docker (or VM) development, simply link your cache folder into your container (or VM).

php:
  image: dmstr/php-yii2:7.0-fpm 
  volumes:
    [...]
    - ~/.composer/cache:/root/.composer/cache

Example Docker image with pre-installed plugins & Yii 2.0 runtime

Using asset-packagist

Asset-packagist is a proxy website which exposes npm and bower packages as composer packages. It works way faster and doesn't require any plugins.

Total 5 comments

#20057 report it
BSCheshir at 2017/03/21 11:49am
composer update / composer install

You get this penalty only once for all your projects developed locally.

for all project of this user (who use link to ~/.composer/cache) its good

If you use composer to update in production you should use a .lock anyway.

yes, IMHO composer install is not use it

size 40k and time ~ 1s8

#20056 report it
schmunk at 2017/03/21 11:37am
Increased disk usage

increase disk usage up to 1400%

Yes, because it needs the git repos to quickly read tags. You get this penalty only once for all your projects developed locally.

If you use composer to update in production you should use a .lock anyway.

#20055 report it
BSCheshir at 2017/03/21 11:12am
increase disk usage up to 1400%

The best way to development, but not for any other!

For example for yii2 project (based at https://github.com/bscheshirwork/docker-yii2-app-advanced-rbac / approx same https://github.com/bscheshirwork/docker-yii2-app-advanced)

for this method

time: 
first run ~ 2m30s, 
second run ~ 20s; 
du -hs ~/.composer is 309mb

for default

time: 
first run ~ 4m40s, 
second run ~ 4m40s; 
du -hs ~/.composer is 21mb

p.s.: alpine image for yii2 is interesting.

#20054 report it
schmunk at 2017/03/21 10:56am
@BSCheshir

You need to update your config settings, but that's just a notice for now, please open an issue here https://github.com/fxpio/composer-asset-plugin/issues if you think further support/docs are required.

#20053 report it
BSCheshir at 2017/03/21 10:11am
update
The "extra.asset-installer-paths" option is deprecated, use the "config.fxp-asset.installer-paths" option
The "extra.asset-pattern-skip-version" option is deprecated, use the "config.fxp-asset.pattern-skip-version" option
The "extra.asset-vcs-driver-options" option is deprecated, use the "config.fxp-asset.vcs-driver-options" option

In your project's composer.json add the following settings to the config section

"config": {
    "fxp-asset": {
        "vcs-driver-options": {
            "github-no-api": true
        },
        "pattern-skip-version": "(-build|-patch)"
    }
},

For example: yii2

"config": {
    "process-timeout": 1800,
    "fxp-asset": {
        "installer-paths": {
            "npm-asset-library": "vendor/npm",
            "bower-asset-library": "vendor/bower"
        },
        "vcs-driver-options": {
            "github-no-api": true
        },
        "pattern-skip-version": "(-build|-patch)"
    }
},

Leave a comment

Please to leave your comment.