Skip to content

Commit c40d069

Browse files
committed
address #1155
1 parent 9d508f1 commit c40d069

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/StaticPHP/Toolchain/ZigToolchain.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ public function afterInit(): void
3636
return;
3737
}
3838
self::$afterInitDone = true;
39-
f_passthru('ulimit -n 2048'); // zig opens extra file descriptors, so when a lot of extensions are built statically, 1024 is not enough
39+
// zig opens extra file descriptors, so when a lot of extensions are built statically, 1024 is not enough
40+
if (function_exists('posix_setrlimit') && function_exists('posix_getrlimit')) {
41+
$limits = posix_getrlimit();
42+
$hard = (int) ($limits['hardopenfiles'] ?? 2048);
43+
$soft = (int) ($limits['softopenfiles'] ?? 1024);
44+
$target = min(max($soft, 2048), $hard > 0 ? $hard : 2048);
45+
if ($target > $soft) {
46+
posix_setrlimit(POSIX_RLIMIT_NOFILE, $target, $hard);
47+
}
48+
}
4049
$cflags = getenv('SPC_DEFAULT_CFLAGS') ?: '';
4150
$cxxflags = getenv('SPC_DEFAULT_CXXFLAGS') ?: '';
4251
$extraCflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') ?: '';

0 commit comments

Comments
 (0)