As I’ve recently taken part into yii2-usuario development (still going very slowly, tough!) one of the most annoying thing was the continuous failing of php 5.6 test on Travis-CI.
The error was not on the app, tough, but a memory exausthed limit during composer install:
$ travis_retry composer install --prefer-dist --no-interaction Loading composer repositories with package information Updating dependencies (including require-dev) PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 32 bytes) in phar:///home/travis/.phpenv/versions/5.6.32/bin/composer/src/Composer/DependencyResolver/Solver.php on line 220 Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 32 bytes) in phar:///home/travis/.phpenv/versions/5.6.32/bin/composer/src/Composer/DependencyResolver/Solver.php on line 220 Check https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors for more info on how to handle out of memory errors.zend_mm_heap corrupted
The linked composer article explains that composer itself raises the memory limit to 1.5G, and indeed that was the reached limit. But how to raise that limit?
So the solution is pretty easy (once understood how Travis-CI works): change the composer install line of your .travis.yml this way:
- COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-dist --no-interaction
That’s it!
Additional note: changing PHP configuration.
At first my approach has been to raise PHP’s memory_limit parameter. But as noted on Stackoverflow it’s not the best way because it could hide memory leaks into the application. I’ll leave it anyway here for documentation. Again the one below is not the best solution.
Travis-CI PHP page explains how to tweak php configuration during builds. The tricky part is to understand when to do it.
As the Build Lifecycle explains before_script is before executing the testing script, and before_install is before installing dependencies. That is!
So let’s add to our .travis.yml:
before_install: - echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
And here we are!