Open_basedir restriction after update to 26

I do not see this as a bug but as a design error.

The number of cpus can, but in this case should not be read from /proc/cpuinfo for the reasons that lead to this issue here. Instead, it should be read with nproc (which is part of coreutils, ie present in the path environment of every Linux system).
For this purpose, the function getHardwareConcurrency() in lib/private/Preview/Generator.php should be changed as follows:

Old:

	/**
	 * Get the number of concurrent threads supported by the host.
	 *
	 * @return int number of concurrent threads, or 0 if it cannot be determined
	 */
	public static function getHardwareConcurrency(): int {
		static $width;
		if (!isset($width)) {
			if (is_file("/proc/cpuinfo")) {
				$width = substr_count(file_get_contents("/proc/cpuinfo"), "processor");
			} else {
				$width = 0;
			}
		}
		return $width;
	}

New:

	/**
	 * Get the number of concurrent threads supported by the host.
	 *
	 * @return int number of concurrent threads, or 0 if it cannot be determined
	 */
	public static function getHardwareConcurrency(): int {
		static $width;
		if (!isset($width)) {
			if (function_exists('exec')) {
				$exec_out = [];
				exec('nproc', $exec_out);
				$width = intval($exec_out[0]);
			} else {
				$width = 0;
			}
		}
		return $width;
	}

Since I am not restricted by PLESK, you could test if this works for you with the following script, which you should place into your webroot:

/home/xxxx/domains/domain.com/public_html/cloud/nproc.php

<?php
require_once 'lib/private/Preview/Generator.php';
use OC\Preview\Generator;
echo 'Hardware concurrency: ' . Generator::getHardwareConcurrency() . "\n";

Now call that script in console with
php /home/xxxx/domains/domain.com/public_html/cloud/nproc.php

it should return an echo like:

Hardware concurrency: 2

(in this example, there are 2 cpus)

If that script runs in your PLESK-restricted environment, you could file an issue for an enhancement (Feature request) here.
You can link to this thread for details.

EDIT: you must test this, since it could be possible, that a function like exec() is restricted (listed as ‘disable_functions = exec’ in php.ini).

You can find out if exec is available on your system with this command:

php -r "echo function_exists('exec') ? 'exec is available' . PHP_EOL : 'exec is not available' . PHP_EOL;"

(you have of course to replace php with the php you are using on your system, like you call the occ command)

3 Likes