Common problems and solutions of php using composer

Table of contents
  • error question one
  • error question two
  • error question three
  • error question four
  • error question five
  • How to use Chinese mirror
  • How to use

Composer is a very good package management tool in PHP, which can help us manage all the packages and plugins that the project needs to depend on, and can also be used to create a project from packagist. However, there will be various problems in the first use. Now I have sorted out the errors and solutions about composer that other developers have asked me as follows, hoping to help you jump into the pit:

error question one

Failed to decode response: zlib_decode(): data error
Retrying with degraded mode. check https://……

The reason for this error is usually the network. Because the statement executed above:

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

This problem occurs when the project installation plugin for yii2 is requested to be installed globally. The composer page provides a workaround for degraded mode. If we enable ipv6, we need to uncheck IPv6.

If this method cannot be used, then you need to use composer Chinese full mirror or other VPN methods.

error question two

The ““file could not be downloaded:
php_network_getaddresses: getaddrinfo failed: No such host known.
failed to open stream: php_network_getaddresses: getaddrinfo failed: no such host known

This is also a relatively classic problem. At this time, when installing composer, you still need to download composer.phar from the official website of composer, so if your website cannot access foreign websites for so long, there will be problems. Of course, you can directly download composer.phar to use it, provided that PHP is added to the environment variable.

error question three

The openssl extension is required for SSL_TLS protection but is not available,If you can not enable the openssl extension you can disable this error. at you own risk, by setting the ‘disable-tls’ option to true

This is a fairly classic mistake. The error is obviously becausephp_openssl is not enabledOpen method is
find your php.ini file find


Remove the preceding semicolon (;). Of course, if this does not take effect, it is possible that multiple php are installed on your computer, so you need to check the PHP path written in the path in the environment variable. Find the php.ini in the path and modify it according to the above process.

error question four

-yiisoft/yii2 2.0.10 requires ext-mbstring * -> the requested PHP extension mbstring is missed

This mistake is also a common mistake. It's because composer installs yii2 and requires mbstring, an extension that handles multibyte strings. The opening method is the same as the previous question, delete the semicolon before php_mbstring.dll


Of course, if it doesn't take effect, you still have to see which PHP path is in the system environment variable.

error question five

Content-Length mismatch

The main reason for this problem is that the requested data is incomplete due to network reasons. The correct way is to use a Chinese mirror library or vpn.

How to use Chinese mirror

The use of Chinese mirrors can basically solve all the above problems (except for the installation of composer), which is also very, very needed.

How to use

After composer is installed, open the command line tool and execute the following statement:

composer config -g repo.packagist composer

This will go to the full Chinese mirror to request the download and installation of packages and plugins.

The above is the detailed content of common problems and solutions of php using composer. For more information about php composer, please pay attention to other related articles on developpaer!