PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / CliMulti / CliPhp.php
matomo / app / core / CliMulti Last commit date
CliPhp.php 2 years ago Output.php 2 years ago OutputInterface.php 2 years ago Process.php 2 years ago RequestCommand.php 2 years ago RequestParser.php 2 years ago StaticOutput.php 2 years ago
CliPhp.php
95 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 */
9 namespace Piwik\CliMulti;
10
11 use Piwik\Common;
12 use Piwik\Config;
13 class CliPhp
14 {
15 public function findPhpBinary()
16 {
17 $general = Config::getInstance()->General;
18 if (!empty($general['php_binary_path']) && file_exists($general['php_binary_path'])) {
19 return $general['php_binary_path'];
20 }
21 if (defined('PHP_BINARY')) {
22 if ($this->isHhvmBinary(PHP_BINARY)) {
23 return PHP_BINARY . ' --php';
24 }
25 if ($this->isValidPhpType(PHP_BINARY)) {
26 return PHP_BINARY . ' -q';
27 }
28 }
29 $bin = '';
30 if (!empty($_SERVER['_']) && Common::isPhpCliMode()) {
31 $bin = $this->getPhpCommandIfValid($_SERVER['_']);
32 }
33 if (empty($bin) && !empty($_SERVER['argv'][0]) && Common::isPhpCliMode()) {
34 $bin = $this->getPhpCommandIfValid($_SERVER['argv'][0]);
35 }
36 if (empty($bin)) {
37 $possiblePhpPath = PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php');
38 $bin = $this->getPhpCommandIfValid($possiblePhpPath);
39 }
40 if (!$this->isValidPhpType($bin) && function_exists('shell_exec')) {
41 $bin = @shell_exec('which php');
42 }
43 if (!$this->isValidPhpType($bin)) {
44 return false;
45 }
46 $bin = trim($bin);
47 if (!$this->isValidPhpVersion($bin)) {
48 return false;
49 }
50 $bin .= ' -q';
51 return $bin;
52 }
53 private function isHhvmBinary($bin)
54 {
55 return false !== strpos($bin, 'hhvm');
56 }
57 private function isValidPhpVersion($bin)
58 {
59 global $piwik_minimumPHPVersion;
60 $cliVersion = $this->getPhpVersion($bin);
61 $isCliVersionValid = $cliVersion && version_compare($piwik_minimumPHPVersion, $cliVersion) <= 0;
62 return $isCliVersionValid;
63 }
64 private function isValidPhpType($path)
65 {
66 if (empty($path)) {
67 return false;
68 }
69 $path = basename($path);
70 return false === strpos($path, 'fpm') && false === strpos($path, 'cgi') && false === strpos($path, 'phpunit') && false === strpos($path, 'lsphp');
71 }
72 private function getPhpCommandIfValid($path)
73 {
74 if (!empty($path) && @is_executable($path)) {
75 if (0 === strpos($path, PHP_BINDIR) && $this->isValidPhpType($path)) {
76 return $path;
77 }
78 }
79 return null;
80 }
81 /**
82 * @param string $bin PHP binary
83 * @return string
84 */
85 private function getPhpVersion($bin)
86 {
87 $command = sprintf("%s -r 'echo phpversion();'", $bin);
88 $version = null;
89 if (function_exists('shell_exec')) {
90 $version = @shell_exec($command);
91 }
92 return $version;
93 }
94 }
95