1

With PHP I'm running into failed to open stream: Too many open files errors, thru wp-cli as well as through fpm-php.

I've adapted things like fpm's rlimit and ulimit on the command line. Now it would be really nice if I can see the maximum number of files a script can open without running the (slow) code.

How can I see the number of file I can open, from PHP itself?

I know I can look at configuration files, but I want to see the actual number that the current script has available so that I can adapt configuration files and see which change actually makes sense.

Unfortunately phpinfo() doesn't show this number.

If there's a shell command that shows this number, this would be good enough of course, as I could just exec that.

the
  • 21,007
  • 11
  • 68
  • 101
  • In /etc/security/limits.conf : not sure – BhAvik Gajjar Nov 21 '19 at 10:24
  • on server debian you can go to also to /etc/php/php7.xx/fpm/pool.d/www.conf find "rlimit_files" then restart the server – BhAvik Gajjar Nov 21 '19 at 10:28
  • 1
    Maximum available file descriptors for a PHP-script seems to be near `posix_getrlimit()['soft_openfiles']` (well, for Linux or POSIX systems), though minus a small though *varying* number of file descriptors (varies per environment, maybe because of files opened internally by PHP or parent processes?). Number of file descriptors in use, you could get by using result of `count(get_resources('stream'))` inside a script. – Wieger Nov 21 '19 at 15:16
  • To correct my previous comment: the underscore in 'soft_openfiles' needs to be a space. – Wieger Nov 21 '19 at 15:26

1 Answers1

0

In php, before the execution, try this

exec('ulimit -S -n 2048');
BhAvik Gajjar
  • 473
  • 3
  • 19
  • This is useful but it doesn't show me the number of maximum open files. In order to avoid adding an extra `exec` to every script, I have to find out which configuration file to change to get the desired effect. – the Nov 21 '19 at 10:43