Symfony/PHP and “Too many open files”

Symfony seems to be somewhat resource hungry under some conditions and would leave trail of PHP errors indicating that there is “Too many open files”.

There are several discussions on the topic suggesting that garbage collection mechanism does not close open files in some cases (ex: ConsoleOutput code).

While it is always good to clean up after yourself when working with file handlers in any code, modifying the production code to address this issue may not be quick solution.

Way around it is to increase file limit in Linux

Using ulimit (SSH)

Note: This may not be very reliable method as most systems would not allow it. But if allowed would be easiest method to address the issue

First, check what the current limit is set to

# ulimit -n

Then if value is too low, try to increase it to desired level by calling (ex: increase from 1024 (default) to 4096)

# ulimit -n 4096

To ensure your system allows root level update using method above and not just updates the session values, restart your SSH session then verify new value is set by calling first command again. If changes reverted back to original, go with the next step.

Adjust limits.conf

This is more “low level” approach – modify values in limits.conf

# vi /etc/security/limits.conf
* soft nofile 1024
* hard nofile 4096

Note: Read the settings format outlined in the file before saving. * may or may not be required.


# vi /etc/sysctl.conf

Reload changes

# sysctl -p

VI command

:w – Save edit
:q! – Exit without save
A – Switch into Insert mode
Esc – Exit insert mode

This entry was posted in CentOS Maintenance, Scratch Pad and tagged , , . Bookmark the permalink.

Leave a Reply

  • About

    From a junior developer through Sr Manager position, I was always interested in new technologies. Passionate speaker, IT junky, developer, architect, team lead, and development manager - many hats, one goal - making software better and being closer to people’s needs. For the most part I am using my blog as a scratch pad, writing small articles on things which I came across, was asked about more then once, and which would otherwise require additional research again and again.

  • Testimonials

    I’ve used your Greydragon theme ever since I switched to using Gallery3. It looks very slick; it does everything that I want; it is easy to customise the appearance with its many options; image preloading makes it faster than other … Continue reading

    Brian Stewart

    The greydragon theme is fantastic. It’s clean, stable and feature rich. It took me a while to decide to move to G3 but with a there like this one, I could no longer resist. Thanks!

  • Categories

%d bloggers like this: