Skip to content

Commit

Permalink
Fix open_basedir preview interaction + simple OS fallback
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Richards <josh.t.richards@gmail.com>
  • Loading branch information
joshtrichards authored Apr 27, 2023
1 parent da274d1 commit 30c5f24
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/private/Preview/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,16 @@ public static function unguardWithSemaphore($semId): bool {
*/
public static function getHardwareConcurrency(): int {
static $width;
// NOTE: This is a no-op anyhow if the admin sets preview_concurrency_* parameters which will override anything based on the below findings
if (!isset($width)) {
if (is_file("/proc/cpuinfo")) {
if (!ini_get('open_basedir') && is_readable("/proc/cpuinfo")) {
// No restrictions and available
$width = substr_count(file_get_contents("/proc/cpuinfo"), "processor");
} else {
// Unable to determine CPU count from OS (will use defaults or configured values)
// Too complicated/taxing to check if entire open_basedir is okay
// Plus issue might be a different OS so punt to defaults
// (possibly overrriden by config anyhow)
$width = 0;
}
}
Expand Down Expand Up @@ -326,6 +332,8 @@ public function getNumConcurrentPreviews(string $type): int {
return $cached[$type];
}

// TODO: Check for configured values and use them before bothering with "guessing"

$hardwareConcurrency = self::getHardwareConcurrency();
switch ($type) {
case "preview_concurrency_all":
Expand Down

0 comments on commit 30c5f24

Please sign in to comment.