Search code examples
phpbuild-processcomposer-php

Better approach to download php composer dependencies


I have been using maven in JAVA and started using PHP Maven, recently I switched to composer.

My project is with Zend Framework 2 and the team only checks in the application code not anything on the vendor directory. This is done to avoid conflicts and not to have the libraries under SVN.

Now each time a developer sets his or her new environment, we observe that, the composer pulls the dependencies from internet. This takes quite a long time.

Is there any better idea/approach to make this faster or handling the project in different way to avoid this problem?

maven uses maven proxy servers which can cache the download and can be used in the network again, but do we have any solutions to handle problems like this?


Solution

  • In PHP there is an existing option for running a composer like repo locally and it's called Satis (it's actually provided by Composer) here: https://github.com/composer/satis

    So you can run it locally on your server and point your composer to use that as a default composer repository and Satis makes sure that all installed packages and different versions are cached on disk as ZIP files so could be retrieved quicker compared to always downloading them from Internet.

    You can do something like this:

    {
        "repositories": [ 
            { 
                "type": "composer", 
                "url": "http://satis.example.org/" 
            }
        ],
        "require": {
            "company/package": "1.2.0",
            "company/package2": "1.5.2",
            "company/package3": "dev-master"
        }
    }
    

    This also allows you to have private packages and libraries without exposing them on GitHub.

    Another BIG advantage is when GitHub goes down for whatever reason you can still deploy as all of your dependancies are cached locally. This is assuming you haven't added new, non-existent packages to the release.