Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

597
Views
PHP Docker - Is it possible to set ulimit at runtime?

On a project I'm working on, xdebug takes approximately 1 hour to generate coverage. I've experimented with phpdbg, but I encounter the following error in my test suite:

stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE.
It is set to 1024, but you have descriptors numbered at least as high as 7228.
 --enable-fd-setsize=8192 is recommended, but you may want to set it
to equal the maximum number of open files supported by your system,
in order to avoid seeing this error again at a later date.

I'm using php:7.0.33-fpm (yes, I know, we're working on upgrading PHP versions :))

Using ulimit in the command line or relying on docker-compose to set it, the output still thinks it's set to 1024. Actually, the current output of ulimit -n within my container is actually over 1 million if I don't try to set it via another mechanism.

Is there any mechanism where this can be set via runtime without having to compile our own php container from scratch?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This warning can be triggered with the following PHP snippet:

<?php

$fds = [];
for ($i = 0; $i < PHP_FD_SETSIZE; $i++) { // PHP_FD_SETSIZE how FD_SETSIZE is exposed to userland
    $fds[] = fopen(__FILE__, 'r');
}

$read = $fds;
$write = [];
$except = [];

echo sprintf("FD_SETSIZE=%d", PHP_FD_SETSIZE) . "\n";

stream_select($read, $write, $except, 0);
/*
 * Warning: stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE.
 * It is set to 1024, but you have descriptors numbered at least as high as 1027.
 *   --enable-fd-setsize=2048 is recommended, but you may want to set it
 * to equal the maximum number of open files supported by your system,
 * in order to avoid seeing this error again at a later date. in /in/ZfBsg on line 14
 */

FD_SETSIZE is a constant defined by POSIX (see the select(2) manpage). While the warning leads you to believe that this warning can be mitigated by recompiling php with --enable-fd-setsize=[some-larger-value], this is not true. FD_SETSIZE cannot be changed at runtime, since its value is determined while compiling the kernel.

I looked at the PHP source code for a bit and I'm not sure why --enable-fd-setsize exists at all, since it does not seem to do anything (although I did not test this on Windows).

The only solutions to this problem seem to be:

  • avoid stream_select
  • avoid opening many files
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!