Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid closure to bump the file descriptor #262

Merged
merged 1 commit into from
Jun 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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