Running Composer update on Ancient code

Ondřej Popelka
3 min readNov 30, 2020

PHP 8.0 was recently released. At the same time, I’m still occasionally working in an archeological dig on a hugely old PHP application. It’s so hugely old that it runs on PHP 5.6 only and depends on a framework which depends on Symfony 2.8 (that’s why it runs on PHP 5.6 only).

On an unfortunate occasion, I also need to use composer to run composer install on this relic and it fails miserably because of exhausted memory. The solution is to run composer update to bring the dependencies forward (there is more than 120 of them) which of course fails miserably too. The usual error is “Allowed memory exhausted”:

PHP Fatal error: Allowed memory size of 5368709120 bytes exhausted (tried to allocate 72 bytes) in phar:///usr/local/bin/composer/src/Composer/DependencyResolver/Rule2Literals.php on line 48

So I can raise the limit to infinity and get “Cannot allocate memory”:

PHP Warning: proc_open(): fork failed — Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 952
Warning: proc_open(): fork failed — Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 952

[ErrorException]
proc_open(): fork failed — Cannot allocate memory

My all-time favorite is the negative allocation though:

That opens a lot of interesting questions — like could I sell, the extra memory I gain this way?

Jokes aside, the only thing I can do is bring the dependencies forward manually. Basically, I must copy the current version to the required version. That doesn’t mean to lock the dependencies, but to bring the minimal version to the current one. PhpStorm is a huge help in this because it shows both the constraint and the current version when editing composer.json:

If the dependencies are under my control, I do this there too — in fact, I must do it for as many dependencies as possible. The more I bring forward, the better chance I have to succeed. In my case, this was the most helpful one:

The most important diff ever

Some libraries are more important than others. Upgrading the requirement for aws/aws-sdk-php: from ~3.2 to ^3.142.1 made the biggest
difference because it skips a huge number of installation possibilities. Packagist for aws-sdk-php, shows that it’s 140 minor versions and around 1000 versions in total. Updating phpunit/phpunit also makes a big difference.

And — that’s it — a lot of annoying and manual work, but with this trick, I can still run composer update on this antique.

P.S. All this applies to Composer V1, although Composer V2 is supposed to be much more effective, but unfortunately it’s incompatible with this antique piece of code. Still Composer is really awesome and I love it!

--

--