Skip to content

Instantly share code, notes, and snippets.

@oanhnn
Created May 14, 2017 16:47
Show Gist options
  • Save oanhnn/112f68e5b91a7dac7641bcd8b0ab13ac to your computer and use it in GitHub Desktop.
Save oanhnn/112f68e5b91a7dac7641bcd8b0ab13ac to your computer and use it in GitHub Desktop.
How to fix composer error "Content-Length Mismatch"

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 in [home] directory, make it like this:

{
  "config": {
    "github-protocols": [
      "https,ssh"
    ]
  },
  "repositories": {
    "packagist": {
      "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": {
      "type": "composer",
      "url": "https://packagist.org"
    }
  }
}

Source: http://stackoverflow.com/questions/38635257/composer-content-length-mismatch

@antonfirdaus
Copy link

thank you.

@danielrubango
Copy link

Good job... It works for me.

@lalitaryan1993
Copy link

composer require kitetail/zttp
Content-Length mismatch, received 16119 bytes out of the expected 1145084
https://repo.packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

@rezmed
Copy link

rezmed commented Mar 23, 2020

Mr-sakr thnks

@felloz
Copy link

felloz commented Apr 10, 2020

@oanhnn I think toay it should be:

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

"packagist.org" instead of "packagist" as also explained in the SO answer you are using as a source.

`The "https://repo.packagist.org/p/provider-2019%24301f2ee16ec6aa29e1b91deb75a805d8329d6579b8a42054396d1b042839ab2b.json" file could not be downloaded: SSL: An existing connection was forcibly closed by the remote host.

failed to open stream: HTTP request failed!
https://repo.packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date
`

@FaithPhilemon
Copy link

Thanks for that, it works!

@amuvavi
Copy link

amuvavi commented Jun 7, 2020

Thanks guys, it worked for me

@LeandroFranciscato
Copy link

LeandroFranciscato commented Jun 8, 2020

On Command, Just change the default repo url to:
composer config -g repo.packagist composer https://packagist.phpcomposer.com

Then It will be solved

@mr-sakr's solution worked for me, but I had to use the second aproach, putting it in my composer.json project file, something like that:

  "repositories": {
    "packagist": {
      "type": "composer",
      "url": "https://packagist.phpcomposer.com"
    }
  }

@Farkhunda
Copy link

Content-Length mismatch, received 66937 bytes out of the expected 999743
http://repo.packagist.org could not be fully loaded, package information was loaded from the local cache and may be out of date

@Farkhunda
Copy link

[Composer\Downloader\TransportException]
Content-Length mismatch, received 243335 bytes out of the expected 1700818

@arinrinrin
Copy link

@mr-sakr thanks, its work!

@theterrificm
Copy link

composer config -g repo.packagist composer https://packagist.phpcomposer.com
.
Thanks. It worked for me

@vinayakkulkarni
Copy link

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

This does the same job :)

@adiparamartha
Copy link

Thankyou @mr-sakr, working like a charm:

currently worked for me: https://packagist.phpcomposer.com

@powertech2nd
Copy link

Awesome, this works for me

@alaa-aqeel
Copy link

php -d memory_limit=-1 /usr/local/bin/composer require */*

@lh948
Copy link

lh948 commented Sep 3, 2020

thanks , that worked for me @mr-sakr

@dylzeee
Copy link

dylzeee commented Sep 24, 2020

Brilliant. Thank you!

@df-a
Copy link

df-a commented Sep 28, 2020

This works. Thanks a ton!

@whitesec-au
Copy link

Nothing works for me. Trying to create a new yii project using composer. Anyone had the same problem with creating a new Yii2 framework project?

@df-a
Copy link

df-a commented Sep 28, 2020

@whitesec-au in my case it was the following

"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.org"
}
}

I had "https://asset-packagist.org" instead of just "https://packagist.org". I changed that and it worked

@Vetjurv4
Copy link

Vetjurv4 commented Nov 5, 2020

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

This does the same job :)

Thank you this worked for me

@ojchris
Copy link

ojchris commented Mar 7, 2021

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

This does the same job :)

This resolved the issue for me

@obiwanpelosi
Copy link

Still getting a content-length mismatch error even after trying the above mentioned solutions. This happens when I'm trying to create a new laravel project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment