This commit is contained in:
Denis Duliçi 2020-10-23 15:15:14 +03:00
parent bf66a5988b
commit f066db31f1

View File

@ -27,19 +27,53 @@ class PhpExecutableFinder
//$this->executableFinder = new ExecutableFinder(); //$this->executableFinder = new ExecutableFinder();
} }
public function getPhpPath()
{
if ($this->isCpanel()) {
return '/usr/local/bin/php';
}
return 'php';
}
public function isCpanel() public function isCpanel()
{ {
return is_dir('/usr/local/cpanel'); return $this->checkFolderAndPort('/usr/local/cpanel', 2082);
} }
public function isPlesk() public function isPlesk()
{ {
return is_dir('/usr/local/psa'); return $this->checkFolderAndPort('/usr/local/psa', 8443);
} }
public function isVirtualmin() public function isVirtualmin()
{ {
return is_dir('/usr/share/webmin'); return $this->checkFolderAndPort('/usr/share/webmin', 10000);
}
public function checkFolderAndPort($folder, $port)
{
try {
return is_dir($folder);
} catch (\ErrorException | \Exception | \Throwable $e) {
return $this->checkSocket($port);
}
}
public function checkSocket($port)
{
try {
$ip = @gethostbyname('localhost');
$link = @fsockopen($ip, $port, $errno, $error);
if ($link) {
return true;
}
return false;
} catch (\ErrorException | \Exception | \Throwable $e) {
return false;
}
} }
/** /**
@ -51,11 +85,7 @@ class PhpExecutableFinder
{ {
# @override # @override
// Not working on shared hosting due to "open_basedir" restriction applied by cPanel/Plesk // Not working on shared hosting due to "open_basedir" restriction applied by cPanel/Plesk
if ($this->isCpanel()) { return $this->getPhpPath();
return '/usr/local/bin/php';
} else {
return 'php';
}
if ($php = getenv('PHP_BINARY')) { if ($php = getenv('PHP_BINARY')) {
if (!is_executable($php)) { if (!is_executable($php)) {