Composer Content-Length Mismatch - composer-php

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 in China: the DNS was poisoned.
So, if you are like me, could there be a way to fix it out?

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

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.

composer config -g repos.packagist composer https://packagist.jp

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.

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.

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

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

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

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

Related

Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.2.5"

I'm trying to upload a plain laravel v5.8 project to a server. It gives me this error
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 7.2.5".
I updated the Laravel version to v6 and it still throws the same thing.
Is there any possible solution I tried many but nothing happens. Thanks in advance.
I faced this problem using the new version of composer, didn't have seen this issue before, although this question is a bit old the solution can help someone else.
I did this working in a development machine, if you really need to change the PHP version running in your server this isn't for you.
This problem is related to a composer configuration when you run the command "composer install" if you need to work with the configuration you already have and don't want to make changes which could lead to other problems you should:
remove the packages you already have installed which includes this configuration from composer
sudo rm -r vendor
run the command again with this flag: --ignore-platform-reqs
composer install --ignore-platform-reqs
Now composer won't perform this check anymore and you are good to go!

composer installing packages command is not defined

I have installed composer on my Synology NAS using this tutorial. I did use PHP73 instead of PHP70 because the package I would like to install requires a minimum of PHP72. It all seems to run fine until I run the following command:
composer require duncan3dc/sonos
This gives me the following error:
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "duncan3dc/sonos" is not defined.
I have already removed composer and reinstalled but without success, so currently my application requiring the package is broken. Very strange because it ran fine before and I don't see where I made changes that could be causing this.
Pretty new at composer btw. I'm running composer 2.0.7 btw.
Solved this by adding the following to my composer.json file and thus forcing composer to use a different version of PHP:
"config": {
"platform": {
"php": "7.3"
}
}

Differences between install via artisan and composer

I found that web.config is included when I install Laravel with:
composer create-project --prefer-dist laravel/laravel blog
but not when I install Laravel using the Laravel installer, with:
laravel new blog
(as per https://laravel.com/docs/5.8/installation)
I've subsequently found a few other differences e.g. devDependencies versions in package.json, some config settings in broadcasting.php, cache.php, database.php.
Can anyone explain to me what is responsible for this difference? Is one install method 'better' than the other?
Thanks
Chris
The difference between both commands is that the composer command uses packagist to get the latest package from GitHub the first time or a cached version, while laravel new blog downloads a zip file from the Laravel server which has the latest version and uses that. Both commands run the so called 'after install' scripts, creating an environment file and setting the application key.
When you don't want a cached version but a new one using composer, run composer clear-cache first, to delete the local cache composer creates.
If you want to see the difference for yourself, compare the composer.json of the base Laravel project (https://www.github.com/laravel/laravel) and the NewCommand.php file in the src directory of the Laravel installer (https://www.github.com/laravel/installer)
Edit
After running both commands, the only difference I could really find was the order in which some things are done, but both generate a working system. Fun thing I noticed is that laravel new project comes with a yarn.lock file, but without a readme.md and composer composer create-project vice versa.

any of composer require command not working

I am using Laravel Valet to creating laravel application because suddenly composer "create-project --prefer-dist laravel/laravel blog" not working.
require command not working.
so I install the valet
The composer is successfully installed on my device Globally. i Follow stap from laravel valet doc to setup composer.
Problem is after composer require command it takes minimum 5min to load
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
and nothing happened I wait 30min and not error or no output
check images composer installed
again wait for 1hour no output and no error
one more example
now how to fix it
This looks like a network error. You should check your network settings, double check if you have access. (I think you have because you posted this question)
There could also be something wrong with the installed composer repositories. If one of those is unavailable it will take forever to load all repositories/search for a repository. You can check which repositories are used with the following command:
composer -g config repositories
composer config repositories
It solved. It was my broadband problem. The connection was alright but it was not able to download package. now it's working.

Class 'Monolog\Logger' not found, installation error in Laravel 4

I installed Laravel without using composer with typing this command:
C:\wamp\www\travail>laravel new project
It seems that it is on the good way.
Creating application...
Application ready! Build something amazing.
But when I tried to open my project here:
wamp-->localhost-->travail-->project-->public
I got this error:
Class 'Monolog\Logger' not found
I solve this issue by doing the following:
Check the minimum-stability value in composer.json and set it to stable:
"minimum-stability": "stable"
Update you composer:
composer self-update
Re-run composer udpate:
composer update
Then run any artisan commands and enjoy coding!
According to this thread. Change minimum-stability from dev to stable in composer.json, then run an update. Also try to do a dump-autoload.
Finally it works for me after running these two commands:
composer self-update
Then:
composer update --no-scripts

Resources