Usage:
You can enable the image service in either of the following ways:
- Add the following configuration information to the configuration file config. JSON of composer (global configuration of the system ). See "Example 1"
- Add the following configuration information to the composer. JSON file of your project (for a single project ). See "Example 2"
To avoid executing two queries during the installation package, you must add the following settings to disable packagist:
{ "repositories": [ {"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false} ] }
Example 1: Modify the composer configuration file
View the main directory of composer:Composer config-L-G
Command to list the global configuration information of composer.[Home]
The configuration item is the main directory of composer. RunSudo composer config-L-G
Command.
Go to the main directory of composer, open the config. JSON file (if there is no such file), and add the configuration information of the Image Service. The final content is as follows:
{ "config": { }, "repositories": [ {"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false} ] }
Example 2: Use the composer. JSON configuration file of the laravel project as an example to add the configuration information of the Image Service as follows (note the last few lines ):
{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "laravel/framework": "4.2.*" }, "autoload": { "classmap": [ "app/commands", "app/controllers", "app/models", "app/database/migrations", "app/database/seeds", "app/tests/TestCase.php" ] }, "scripts": { "post-install-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-update-cmd": [ "php artisan clear-compiled", "php artisan optimize" ], "post-create-project-cmd": [ "php artisan key:generate" ] }, "config": { "preferred-install": "dist" }, "minimum-stability": "stable", "repositories": [ {"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"}, {"packagist": false} ] }
Note:
Using this image service means that all the downloaded installation package metadata will come from this image service and will not initiate a request to packagist.org. This will accelerate the installation process of composer and make it more reliable and fast. (Due to the well-known reasons, the connection speed of foreign websites is too slow and may be blocked at any time)
Generally, the data of the installation package (such as ZIP files) is downloaded from GitHub or other third-party servers. After using this image service, we will cache all installation packages to data centers in China, in this way, you no longer need to send requests to foreign websites. Therefore, even if packagist.org, github.com, or other third-party services fail (the connection speed is too slow and the connection is blocked ), you can still download and update the installation package.
[Switch] Composer China Image