Making Local Development Faster with Caches for NPM & Composer (Part Two: Composer)

If you’re a heavy PHP user, you’ll most likely be using quite a bit during your development cycles. A quick win in speeding this up is using a local cache for Packagist which means you’re only downloading across your local network instead of across the Internet.

You can run a local toran proxy instance by running this command:

docker run --name toran-proxy -d -p 82:80 -v /opt/toran-proxy:/data/toran-proxy -e "TORAN_CRON_TIMER=half" -e "TORAN_TOKEN_GITHUB=8ba3e80d61fb" -e "TORAN_PHP_TIMEZONE=Europe/London" -e "TORAN_HOST=toran.local:82" cedvan/toran-proxy:1.1.7-1

We can break this down a little bit. The volume mount means that we have persistence with our cache and settings. We use port 82 and the hostname of toran.local. This means that we can add the following the to our projects composer.json:

"repositories": [
    {"type": "composer", "url": "http://toran.local:82/repo/packagist/"},
    {"packagist": false}

Your local composer will now begin to use your toran proxy instance. You can read more information about the Docker image used here over at the Github repo or on the Docker hub page.

You can read the first part of this series detailing an NPM cache here.