Composer Content-Length Mismatch

前端 未结 11 1534
暗喜
暗喜 2020-11-28 06:03

Sometimes when I run composer update to upgrade the laravel project, a content-length mismatch exception might occur. Finally, I get this is because of the terrible firewall

相关标签:
11条回答
  • 2020-11-28 06:40

    I tried accepted answer and it was not working for me, and I tried answer from macbert and same issue, Also tried uninstall and install fresh composer. Anyway thanks to macbert and Alex Chiang I figured another solution.

    I think the problem is my composer cannot download data from packagist.org server, so I changed server into a mirror. Run following command on cmd to change into mirror (I got this mirror from here)

    composer config -g repo.packagist composer https://repo-eu-uk-1.packagist.org
    

    If this is not working for you try some other mirror from https://packagist.org/mirrors

    Anyway I listed down the same list here even if you cannot load the above link

    • Africa, South Africa

      composer config -g repos.packagist composer https://packagist.co.za
      
    • Asia, China

      composer config -g repos.packagist composer https://mirrors.huaweicloud.com/repository/php
      
    • Asia, China

      composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
      
    • Asia, China

      composer config -g repos.packagist composer https://php.cnpkg.org
      
    • Asia, China

      composer config -g repo.packagist composer https://packagist.phpcomposer.com
      
    • Asia, China

      composer config -g repos.packagist composer https://packagist.mirrors.sjtug.sjtu.edu.cn
      
    • Asia, China

      composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/
      
    • Asia, India

      composer config -g repo.packagist composer packagist.in
      
    • Asia, India

      composer config -g repos.packagist composer https://packagist.in
      
    • Asia, Indonesia

      composer config -g repos.packagist composer https://packagist.vrkansagara.in
      
    • Asia, Japan

      composer config -g repos.packagist composer https://packagist.jp
      
    • Asia, South Korea

      composer config -g repos.packagist composer https://packagist.kr
      
    • Asia, Thailand

      composer config -g repos.packagist composer https://packagist.mycools.in.th/
      
    • South America, Brazil

      composer config -g repos.packagist composer https://packagist.com.br
      

    NOTE: I didn't try all the mirrors, you may try one by one if it is not working for you.

    0 讨论(0)
  • 2020-11-28 06:42

    Laravel Error Content Length mismatch Solution Only Need to run some commands

    0 讨论(0)
  • 2020-11-28 06:44

    Had some same issues based from the Github source you may also use

    composer self-update --snapshot
    

    this might produce this:

    but after that it will automatically proceed and download

    0 讨论(0)
  • 2020-11-28 06:45

    First, run:

    composer config --list --global          //this will get the composer home path.
    [home] /root/.composer                   //it's my composer home path.
    

    And then, edit the config.json, make it like this:

    {
      "config": {
        "github-protocols": [
          "https"
        ]
      },
      "repositories": {
        "packagist.org": {
          "type": "composer",
          "url": "https://packagist.org"
        }
      }
    }
    

    It will make the packagist connection force https. And also you could config the composer.json in your project, this is a laravel sample would be look like:

    {
      "name": "laravel/laravel",
      "description": "The Laravel Framework.",
      "keywords": [
        "framework",
        "laravel"
      ],
      "license": "MIT",
      "type": "project",
      "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*"
      },
      "config": {
        "preferred-install": "dist"
      },
      "repositories": {
        "packagist.org": {
          "type": "composer",
          "url": "https://packagist.org"
        }
      }
    }
    

    Update

    Before Composer v1.2.3 the repository key for packagist was "packagist". In v1.2.3 it was changed to "packagist.org" (see commit e38ebef).

    0 讨论(0)
  • 2020-11-28 06:45

    Just change the composer default repo url:

    composer config -g repo.packagist composer https://packagist.org
    composer config -g github-protocols https ssh
    

    It changes or sets the packagist repo to be used by https only.

    This fixes any issues with local composer.json files too. No need to mess around with the composer.json file localy or global.

    0 讨论(0)
  • 2020-11-28 06:45

    I had the same issue, i did two things

    first updated composer, it was 1.4 updated to 1.7

    secondly, change internet connection to high speed.

    0 讨论(0)
提交回复
热议问题