If you are performing unit tests on large PHP applications with PHPUnit, you may encounter the error “Too many open files”. It happens, don’t take it personally.

This error occurs because the OS sets a maximum number of files (also known as file descriptors) allowed to be opened by a process, and inevitably this will lead to problems when you try to go over this number. When a process reaches this limit, the process fails and your tests are not completed accurately.

The simple fix for this is to increase the limit of file descriptors that a process can open. We can do this by executing the command ulimit in the terminal, as follows:

$ ulimit -n 10000

This will apply only for the current session, and not the system in general, and now our test suite should run without problems.

The ulimit command is available in Linux and Mac OSX. Happy testing!