The “Too many open files” error can occur in PHP-fpm when the system limit for open file descriptors is reached. To resolve this issue, you can increase the limit for open file descriptors in the system. Here’s how to increase the open file descriptor limit in PHP-fpm:
- Find the current open file descriptor limit: You can check the current open file descriptor limit by running the following command:
ulimit -n
This will give you the current limit for open file descriptors.
- Modify the open file descriptor limit: To increase the open file descriptor limit, you can modify the
/etc/security/limits.conf
file. Open the file with a text editor and add the following lines:
* soft nofile 65536
* hard nofile 65536
Replace 65536 with the desired limit for open file descriptors.
- Restart PHP-fpm: After modifying the
limits.conf
file, restart PHP-fpm to apply the changes. You can restart PHP-fpm by running the following command:
# service php7.4-fpm restart
Replace “php7.4-fpm” with the name of your PHP-fpm service.
- Verify the new limit: You can verify the new limit for open file descriptors by running the following command:
ulimit -n
This should give you the new limit for open file descriptors that you set in the limits.conf
file.
That’s it! You have now increased the limit for open file descriptors in PHP-fpm. This should resolve the “Too many open files” error in PHP-fpm.