Composer Content-Length Mismatch

孤街浪徒 提交于 2019-11-27 03:41:50
Alex Chiang

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).

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.

I had the same issue so I came here though google search.

I run composer commands both on my local machine and docker machine. I received a variety of errors on each machine when running composer install including Composer Content-Length Mismatch.

I started to mess with my composer.json file as recommended, then I realized the macbook lost it's wifi connection, like it loves to do. Additionally I am on a poor network as I am traveling. I also was warned my composer was out of date on my local machine, which I should have been using my docker VM to issue the commands anyway. My docker workspace container had not been updated for a year.

I got the wifi connection back, upgraded composer on my local machine and composer install ran just fine. I assume if I upgrade docker config that it will work there as well.

I had the same problem while installing laravel on my Windows machine, I was using git bash for running following command.

composer global require "laravel/installer=~1.1"

I switched to the normal command prompt then it worked without any errors.

Sofia Mallari

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

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.

Solved the same issue by simply upgrading zlib(1g) [deb]

(more precisely, from trusty/14.04 to xenial/16.04, both are LTS of course ;-)

I know that's an old one, but I faced this issue for the first today.

I'm not sure if the answer here is partially helping or not, but I keep getting the same errors anyway.

The difference (though, again, it might be just a coincidence) is that further attempts seems to be partially successful: - The already downloaded JSON are retrieved from the cache (I don't dare clearing the cache now) - Some of previously failed ones are downloaded with success - Other are still failing

I suppose that if I keep trying, I'll eventually manage to download all the JSON files.

It's clear that the problem is that Composer is unable to download the complete file (which is indeed quite big). I don't think is a network issue from my side: as far as I can see, it works just fine as it always did.

What I don't understand is what changed from yesterday that makes Composer behaves like that: I didn't update Composer, PHP or other things.

Also, even supposing that I'll eventually manage to let Composer download all these huge files, the first time I'll clear the cache, I'll likely face the same problem again.

I wonder if, at least in my case, the problem is elsewhere, because all the answer I could find are pointing here and everyone seems to solve the problem: no more errors and quick downloads of these JSON files (which is not my case).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!