Simply Testable Blog

Figuring out how to automate away the pain of routine front-end web testing; the story behind SimplyTestable.com.

211 posts covering the initial idea, growth of the service, features, advances, failures and successes.

Introduction

I use Travis CI as a secondary continuous integration (CI) service to help ensure that each Simply Testable application works in isolation as expected when code changes are made.

Following some recent changes I noticed that the PHP 5.3 build failed due to it hitting a memory limit running unit tests.

The most straightforward course of action: increase the PHP memory limit in the Travis environment.

Each Travis build runs in a fresh virtual machine for which any form of shell access is not available. Simply finding and updating a configuration file isn't an option.

Despite that, making the change is really easy. Here's what you do.

Appending Any PHP Configuration Setting For Travis

Thankfully the Travis CI documentation is awesome and it provides a clear means of appending the standard PHP configuration with your own custom settings.

We can use this to set the PHP memory limit.

Setting the PHP Memory Limit for Travis CI

  1. Create your custom ini file

    I created a file named travis.php.ini in the root of my project (at the same level as .travis.yml.

    Name yours however you choose and put it within your project wherever you choose; the above is just an example. The important part is to note the relative path to your ini file.

    Add to your ini file any custom PHP configuration settings. These follow the same format as a regular php.ini file.

    I added just the following:

    memory_limit = 1024M
  2. Update your project Travis configuration

    You need to add phpenv config-add <relative path to your ini file> to the before_script section of your .travis.yml.

    Here's an abridged copy of my current .travis.yml to show what that looks like:

    language: php
    php:
      - 5.3
      - 5.4
      - 5.5
      
    before_script:
      # Additional PHP config
      - phpenv config-add travis.php.ini
      
      # ... additional script lines  
    
    script:
      - phpunit -c app

    So long as yours looks similar to the above but retains the ini file naming you chose you should be fine.