Skip to content

Commit

Permalink
Fix invalid closure to bump the file descriptor (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Jun 17, 2018
1 parent 37699fe commit ada42d7
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/Console/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,35 +609,37 @@ private function bumpOpenFileDescriptorLimit(Box $box, SymfonyStyle $io): callab
{
$filesCount = count($box) + 128; // Add a little extra for good measure

if (function_exists('posix_getrlimit') && function_exists('posix_setrlimit')) {
$softLimit = posix_getrlimit()['soft openfiles'];
$hardLimit = posix_getrlimit()['hard openfiles'];

if ($softLimit < $filesCount) {
$io->writeln(
sprintf(
'<info>[debug] Increased the maximum number of open file descriptors from ("%s", "%s") to ("%s", "%s")'
.'</info>',
$softLimit,
$hardLimit,
$filesCount,
'unlimited'
),
OutputInterface::VERBOSITY_DEBUG
);

posix_setrlimit(
POSIX_RLIMIT_NOFILE,
$filesCount,
'unlimited' === $hardLimit ? POSIX_RLIMIT_INFINITY : $hardLimit
);
}
} else {
if (false === function_exists('posix_getrlimit') || false === function_exists('posix_setrlimit')) {
$io->writeln(
'<info>[debug] Could not check the maximum number of open file descriptors: the functions "posix_getrlimit()" and '
.'"posix_setrlimit" could not be found.</info>',
OutputInterface::VERBOSITY_DEBUG
);

return function () {};
}

$softLimit = posix_getrlimit()['soft openfiles'];
$hardLimit = posix_getrlimit()['hard openfiles'];

if ($softLimit < $filesCount) {
$io->writeln(
sprintf(
'<info>[debug] Increased the maximum number of open file descriptors from ("%s", "%s") to ("%s", "%s")'
.'</info>',
$softLimit,
$hardLimit,
$filesCount,
'unlimited'
),
OutputInterface::VERBOSITY_DEBUG
);

posix_setrlimit(
POSIX_RLIMIT_NOFILE,
$filesCount,
'unlimited' === $hardLimit ? POSIX_RLIMIT_INFINITY : $hardLimit
);
}

return function () use ($io, $softLimit, $hardLimit): void {
Expand Down

0 comments on commit ada42d7

Please sign in to comment.